Skip to content

Commit f0a3283

Browse files
Copilotdinwwwh
andcommitted
fix: change SHORTABLE_ORIGIN from orpc:// to http://orpc for Android WebView compatibility
Co-authored-by: unnoq <64189902+unnoq@users.noreply.github.com>
1 parent 78b2a11 commit f0a3283

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

packages/standard-server-peer/src/codec.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('serializeRequestMessage & deserializeRequestMessage', () => {
1212
it('should serialize and deserialize a basic POST request', () => {
1313
const id = 'req-123'
1414
const payload: RequestMessageMap[MessageType.REQUEST] = {
15-
url: new URL('orpc://localhost/api/users'),
15+
url: new URL('http://orpc/api/users'),
1616
method: 'POST',
1717
headers: { 'content-type': 'application/json' },
1818
body: { name: 'John' },
@@ -34,7 +34,7 @@ describe('serializeRequestMessage & deserializeRequestMessage', () => {
3434

3535
expect(decodedId).toBe(id)
3636
expect(decodedType).toBe(MessageType.REQUEST)
37-
expect(decodedPayload.url.toString()).toBe('orpc://localhost/api/users')
37+
expect(decodedPayload.url.toString()).toBe('http://orpc/api/users')
3838
expect(decodedPayload.method).toBe('POST')
3939
expect(decodedPayload.headers).toEqual({ 'content-type': 'application/json' })
4040
expect(decodedPayload.body).toEqual({ name: 'John' })
@@ -75,7 +75,7 @@ describe('serializeRequestMessage & deserializeRequestMessage', () => {
7575
const blobData = new Blob(['test content'], { type: 'text/plain' })
7676

7777
const payload: RequestMessageMap[MessageType.REQUEST] = {
78-
url: new URL('orpc://localhost/upload'),
78+
url: new URL('http://orpc/upload'),
7979
method: 'POST',
8080
headers: { 'content-type': 'text/plain' },
8181
body: blobData,
@@ -140,7 +140,7 @@ describe('serializeRequestMessage & deserializeRequestMessage', () => {
140140
it('should omit empty headers and default POST method', () => {
141141
const id = 'req-minimal'
142142
const payload: RequestMessageMap[MessageType.REQUEST] = {
143-
url: new URL('orpc://localhost/test'),
143+
url: new URL('http://orpc/test'),
144144
method: 'POST',
145145
headers: {},
146146
body: 'data',
@@ -337,12 +337,12 @@ describe('encode/decode request message', () => {
337337
})
338338

339339
describe.each([
340-
['GET', new URL('orpc://localhost/api/v1/users/1?a=1&b=2'), {}],
341-
['GET', new URL('orpc:///localhost/api/v1/users/1?a=1&b=2'), {}],
342-
['GET', new URL('orpc://example.com/api/v1/users/1?a=1&b=2'), {}],
343-
['GET', new URL('orpc:///example.com/api/v1/users/1?a=1&b=2'), {}],
344-
['GET', new URL('orpc:/api/v1/users/1?a=1&b=2'), {}],
345-
['GET', new URL('orpc://api/v1/users/1?a=1&b=2'), {}],
340+
['GET', new URL('http://orpc/api/v1/users/1?a=1&b=2'), {}],
341+
['GET', new URL('http:///orpc/api/v1/users/1?a=1&b=2'), {}],
342+
['GET', new URL('http://example.com/api/v1/users/1?a=1&b=2'), {}],
343+
['GET', new URL('http:///example.com/api/v1/users/1?a=1&b=2'), {}],
344+
['GET', new URL('http:/api/v1/users/1?a=1&b=2'), {}],
345+
['GET', new URL('http://api/v1/users/1?a=1&b=2'), {}],
346346
['GET', new URL('https://example.com/api/v1/users/1?a=1&b=2'), {}],
347347
['POST', new URL('https://example.com/api/v1/users/1'), { 'x-custom-header': 'value' }],
348348
['DELETE', new URL('https://example.com/api/v1/users/1'), { }],

packages/standard-server-peer/src/codec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type { EncodedMessage } from './types'
33
import { isAsyncIteratorObject, readAsBuffer, stringifyJSON } from '@orpc/shared'
44
import { flattenHeader, generateContentDisposition, getFilenameFromContentDisposition } from '@orpc/standard-server'
55

6-
const SHORTABLE_ORIGIN = 'orpc://localhost'
7-
const SHORTABLE_ORIGIN_MATCHER = /^orpc:\/\/localhost\//
6+
const SHORTABLE_ORIGIN = 'http://orpc'
7+
const SHORTABLE_ORIGIN_MATCHER = /^http:\/\/orpc\//
88

99
export enum MessageType {
1010
REQUEST = 1,
@@ -57,7 +57,7 @@ export interface SerializedRequestPayload {
5757
/**
5858
* The url of the request
5959
*
60-
* might be relative path if origin is `orpc://localhost`
60+
* might be relative path if origin is `http://orpc`
6161
*/
6262
u: string
6363

0 commit comments

Comments
 (0)