From 032faefa4bc0c3bf065efaec12a3cfc67755fcda Mon Sep 17 00:00:00 2001 From: Jeremy Wharton Date: Wed, 15 Nov 2023 01:06:11 -0600 Subject: [PATCH] private/apigen: fix URL construction in generated TypeScript code This change fixes an incorrect invocation of the URL object constructor in generated TypeScript HTTP clients. Change-Id: I9011bc535f2096374d20b74b401d4cc38a0451fb --- private/apigen/example/client-api.gen.ts | 2 +- private/apigen/tsgen.go | 2 +- web/satellite/src/api/v0.gen.ts | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/private/apigen/example/client-api.gen.ts b/private/apigen/example/client-api.gen.ts index 264929a37..260eb8575 100644 --- a/private/apigen/example/client-api.gen.ts +++ b/private/apigen/example/client-api.gen.ts @@ -114,7 +114,7 @@ export class DocumentsHttpApiV0 { } public async updateContent(request: DocsUpdateContentRequest, path: string, id: UUID, date: Time): Promise { - const u = new URL(`${this.ROOT_PATH}/${path}`); + const u = new URL(`${this.ROOT_PATH}/${path}`, window.location.href); u.searchParams.set('id', id); u.searchParams.set('date', date); const fullPath = u.toString(); diff --git a/private/apigen/tsgen.go b/private/apigen/tsgen.go index d20e28cd3..5770ebabb 100644 --- a/private/apigen/tsgen.go +++ b/private/apigen/tsgen.go @@ -114,7 +114,7 @@ func (f *tsGenFile) createAPIClient(group *EndpointGroup) { f.pf("\tpublic async %s(%s): Promise<%s> {", method.TypeScriptName, funcArgs, returnType) if len(method.QueryParams) > 0 { - f.pf("\t\tconst u = new URL(`%s`);", path) + f.pf("\t\tconst u = new URL(`%s`, window.location.href);", path) for _, p := range method.QueryParams { f.pf("\t\tu.searchParams.set('%s', %s);", p.Name, p.Name) } diff --git a/web/satellite/src/api/v0.gen.ts b/web/satellite/src/api/v0.gen.ts index 66cd23fb8..e94b82907 100644 --- a/web/satellite/src/api/v0.gen.ts +++ b/web/satellite/src/api/v0.gen.ts @@ -148,7 +148,7 @@ export class ProjectManagementHttpApiV0 { } public async getBucketRollup(projectID: UUID, bucket: string, since: Time, before: Time): Promise { - const u = new URL(`${this.ROOT_PATH}/bucket-rollup`); + const u = new URL(`${this.ROOT_PATH}/bucket-rollup`, window.location.href); u.searchParams.set('projectID', projectID); u.searchParams.set('bucket', bucket); u.searchParams.set('since', since); @@ -163,7 +163,7 @@ export class ProjectManagementHttpApiV0 { } public async getBucketRollups(projectID: UUID, since: Time, before: Time): Promise { - const u = new URL(`${this.ROOT_PATH}/bucket-rollups`); + const u = new URL(`${this.ROOT_PATH}/bucket-rollups`, window.location.href); u.searchParams.set('projectID', projectID); u.searchParams.set('since', since); u.searchParams.set('before', before); @@ -177,7 +177,7 @@ export class ProjectManagementHttpApiV0 { } public async getAPIKeys(projectID: UUID, search: string, limit: number, page: number, order: number, orderDirection: number): Promise { - const u = new URL(`${this.ROOT_PATH}/apikeys/${projectID}`); + const u = new URL(`${this.ROOT_PATH}/apikeys/${projectID}`, window.location.href); u.searchParams.set('search', search); u.searchParams.set('limit', limit); u.searchParams.set('page', page);