Skip to content

Commit 4038fb9

Browse files
authored
feat(client): support search query in base url (#324)
1 parent b5b7502 commit 4038fb9

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

packages/client/src/adapters/standard/rpc-link-codec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ export class StandardRPCLinkCodec<T extends ClientContext> implements StandardLi
7878
const expectedMethod = await value(this.expectedMethod, options, path, input)
7979
let headers = await value(this.headers, options, path, input)
8080
const baseUrl = await value(this.baseUrl, options, path, input)
81-
const url = new URL(`${baseUrl.toString().replace(/\/$/, '')}${toHttpPath(path)}`)
81+
const url = new URL(baseUrl)
82+
url.pathname = `${url.pathname.replace(/\/$/, '')}${toHttpPath(path)}`
8283

8384
if (options.lastEventId !== undefined) {
8485
headers = mergeStandardHeaders(headers, { 'last-event-id': options.lastEventId })

packages/openapi-client/src/adapters/standard/openapi-link-codec.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ export class StandardOpenapiLinkCodec<T extends ClientContext> implements Standa
5858
const inputStructure = fallbackContractConfig('defaultInputStructure', procedure['~orpc'].route.inputStructure)
5959

6060
return inputStructure === 'compact'
61-
? this.#encodeCompact(procedure, path, input, options, baseUrl.toString(), headers)
62-
: this.#encodeDetailed(procedure, path, input, options, baseUrl.toString(), headers)
61+
? this.#encodeCompact(procedure, path, input, options, baseUrl, headers)
62+
: this.#encodeDetailed(procedure, path, input, options, baseUrl, headers)
6363
}
6464

6565
#encodeCompact(
6666
procedure: AnyContractProcedure,
6767
path: readonly string[],
6868
input: unknown,
6969
options: ClientOptions<T>,
70-
baseUrl: string,
70+
baseUrl: string | URL,
7171
headers: StandardHeaders,
7272
): StandardRequest {
7373
let httpPath = standardizeHTTPPath(procedure['~orpc'].route.path ?? toHttpPath(path))
@@ -92,7 +92,8 @@ export class StandardOpenapiLinkCodec<T extends ClientContext> implements Standa
9292
}
9393

9494
const method = fallbackContractConfig('defaultMethod', procedure['~orpc'].route.method)
95-
const url = new URL(`${baseUrl.toString().replace(/\/$/, '')}${httpPath}`)
95+
const url = new URL(baseUrl)
96+
url.pathname = `${url.pathname.replace(/\/$/, '')}${httpPath}`
9697

9798
if (method === 'GET') {
9899
const serialized = this.serializer.serialize(httpBody, { outputFormat: 'URLSearchParams' }) as URLSearchParams
@@ -124,7 +125,7 @@ export class StandardOpenapiLinkCodec<T extends ClientContext> implements Standa
124125
path: readonly string[],
125126
input: unknown,
126127
options: ClientOptions<T>,
127-
baseUrl: string,
128+
baseUrl: string | URL,
128129
headers: StandardHeaders,
129130
): StandardRequest {
130131
let httpPath = standardizeHTTPPath(procedure['~orpc'].route.path ?? toHttpPath(path))
@@ -156,7 +157,8 @@ export class StandardOpenapiLinkCodec<T extends ClientContext> implements Standa
156157
}
157158

158159
const method = fallbackContractConfig('defaultMethod', procedure['~orpc'].route.method)
159-
const url = new URL(`${baseUrl.toString().replace(/\/$/, '')}${httpPath}`)
160+
const url = new URL(baseUrl)
161+
url.pathname = `${url.pathname.replace(/\/$/, '')}${httpPath}`
160162

161163
if (input?.query !== undefined) {
162164
const query = this.serializer.serialize(input.query, { outputFormat: 'URLSearchParams' }) as URLSearchParams

0 commit comments

Comments
 (0)