Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/client/src/adapters/message-port/rpc-link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('rpcLink', () => {

expect(id).toBeTypeOf('string')
expect(payload).toEqual({
url: new URL('orpc:/ping'),
url: new URL('orpc://localhost/ping'),
body: { json: 'input' },
headers: {},
method: 'POST',
Expand All @@ -56,7 +56,7 @@ describe('rpcLink', () => {

expect(id).toBeTypeOf('string')
expect(payload).toEqual({
url: new URL('orpc:/ping'),
url: new URL('orpc://localhost/ping'),
body: expect.any(FormData),
headers: expect.any(Object),
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/adapters/message-port/rpc-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export interface RPCLinkOptions<T extends ClientContext>
export class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
constructor(options: RPCLinkOptions<T>) {
const linkClient = new LinkMessagePortClient(options)
super(linkClient, { ...options, url: 'orpc:/' })
super(linkClient, { ...options, url: 'orpc://localhost' })
}
}
4 changes: 2 additions & 2 deletions packages/client/src/adapters/websocket/rpc-link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('rpcLink', () => {

expect(id).toBeTypeOf('string')
expect(payload).toEqual({
url: new URL('orpc:/ping'),
url: new URL('orpc://localhost/ping'),
body: { json: 'input' },
headers: {},
method: 'POST',
Expand All @@ -56,7 +56,7 @@ describe('rpcLink', () => {

expect(id).toBeTypeOf('string')
expect(payload).toEqual({
url: new URL('orpc:/ping'),
url: new URL('orpc://localhost/ping'),
body: { json: 'input' },
headers: {},
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/adapters/websocket/rpc-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
constructor(options: RPCLinkOptions<T>) {
const linkClient = new LinkWebsocketClient(options)

super(linkClient, { ...options, url: 'orpc:/' })
super(linkClient, { ...options, url: 'orpc://localhost' })
}
}
2 changes: 1 addition & 1 deletion packages/server/src/adapters/bun-ws/rpc-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('rpcHandler', async () => {
}

const string_request_message = await encodeRequestMessage('19', MessageType.REQUEST, {
url: new URL('orpc:/ping'),
url: new URL('orpc://localhost/ping'),
body: { json: 'input' },
headers: {},
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/adapters/crossws/rpc-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('rpcHandler', async () => {

const ping_request_message = {
rawData: await encodeRequestMessage('19', MessageType.REQUEST, {
url: new URL('orpc:/ping'),
url: new URL('orpc://localhost/ping'),
body: { json: 'input' },
headers: {},
method: 'POST',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('rpcHandler', async () => {
})

const string_request_message = await encodeRequestMessage('19', MessageType.REQUEST, {
url: new URL('orpc:/ping'),
url: new URL('orpc://localhost/ping'),
body: { json: 'input' },
headers: {},
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/adapters/websocket/rpc-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('rpcHandler', async () => {

const string_request_message = {
data: await encodeRequestMessage('19', MessageType.REQUEST, {
url: new URL('orpc:/ping'),
url: new URL('orpc://localhost/ping'),
body: { json: 'input' },
headers: {},
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/adapters/ws/rpc-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('rpcHandler', async () => {

const string_request_message = {
data: await encodeRequestMessage('19', MessageType.REQUEST, {
url: new URL('orpc:/ping'),
url: new URL('orpc://localhost/ping'),
body: { json: 'input' },
headers: {},
method: 'POST',
Expand Down
2 changes: 2 additions & 0 deletions packages/standard-server-peer/src/codec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ describe('encode/decode request message', () => {
})

describe.each([
['GET', new URL('orpc://localhost/api/v1/users/1?a=1&b=2'), {}],
['GET', new URL('orpc:///localhost/api/v1/users/1?a=1&b=2'), {}],
['GET', new URL('orpc://example.com/api/v1/users/1?a=1&b=2'), {}],
['GET', new URL('orpc:///example.com/api/v1/users/1?a=1&b=2'), {}],
['GET', new URL('orpc:/api/v1/users/1?a=1&b=2'), {}],
Expand Down
14 changes: 11 additions & 3 deletions packages/standard-server-peer/src/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type { EncodedMessage } from './types'
import { isAsyncIteratorObject, readAsBuffer, stringifyJSON } from '@orpc/shared'
import { flattenHeader, generateContentDisposition, getFilenameFromContentDisposition } from '@orpc/standard-server'

const SHORTABLE_ORIGIN = 'orpc://localhost'
const SHORTABLE_ORIGIN_MATCHER = /^orpc:\/\/localhost\//

export enum MessageType {
REQUEST = 1,
RESPONSE = 2,
Expand Down Expand Up @@ -54,7 +57,7 @@ interface SerializedRequestPayload {
/**
* The url of the request
*
* might be relative path if it starts with `orpc:/`
* might be relative path if origin is `orpc://localhost`
Comment thread
dinwwwh marked this conversation as resolved.
*/
u: string

Expand Down Expand Up @@ -120,7 +123,7 @@ export async function encodeRequestMessage<T extends keyof RequestMessageMap>(
)

const serializedPayload: SerializedRequestPayload = {
u: request.url.toString().replace(/^orpc:\//, '/'),
u: request.url.toString().replace(SHORTABLE_ORIGIN_MATCHER, '/'),
b: processedBody instanceof Blob ? undefined : processedBody,
h: Object.keys(processedHeaders).length > 0 ? processedHeaders : undefined,
m: request.method === 'POST' ? undefined : request.method,
Expand Down Expand Up @@ -159,7 +162,12 @@ export async function decodeRequestMessage(raw: EncodedMessage): Promise<Decoded
const headers = payload.h ?? {}
const body = await deserializeBody(headers, payload.b, buffer)

return [id, MessageType.REQUEST, { url: new URL(payload.u, 'orpc:/'), headers, method: payload.m ?? 'POST', body }]
return [id, MessageType.REQUEST, {
url: payload.u.startsWith('/') ? new URL(`${SHORTABLE_ORIGIN}${payload.u}`) : new URL(payload.u),
headers,
method: payload.m ?? 'POST',
body,
}]
Comment thread
dinwwwh marked this conversation as resolved.
}

export async function encodeResponseMessage<T extends keyof ResponseMessageMap>(
Expand Down
Loading