From 2ee2a90aebcf75a0df467c47a5f731b07ce69070 Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Tue, 20 Aug 2024 01:10:34 +0300 Subject: [PATCH] Allow a custom path in Firebase functions custom domain (#8441) * Allow a custom path in Firebase functions custom domain * Add a test * Add changeset * Update packages/functions/src/service.ts Co-authored-by: Daniel La Rocque --------- Co-authored-by: Daniel La Rocque --- .changeset/dull-nails-kneel.md | 5 +++++ packages/functions/src/service.test.ts | 5 +++++ packages/functions/src/service.ts | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/dull-nails-kneel.md diff --git a/.changeset/dull-nails-kneel.md b/.changeset/dull-nails-kneel.md new file mode 100644 index 00000000000..09403953549 --- /dev/null +++ b/.changeset/dull-nails-kneel.md @@ -0,0 +1,5 @@ +--- +'@firebase/functions': patch +--- + +Allow a custom path in Firebase functions custom domain diff --git a/packages/functions/src/service.test.ts b/packages/functions/src/service.test.ts index 1a43b32136f..bb29f9025fe 100644 --- a/packages/functions/src/service.test.ts +++ b/packages/functions/src/service.test.ts @@ -70,6 +70,11 @@ describe('Firebase Functions > Service', () => { assert.equal(service._url('foo'), 'https://mydomain.com/foo'); }); + it('correctly sets custom domain with path', () => { + service = createTestService(app, 'https://mydomain.com/functions'); + assert.equal(service._url('foo'), 'https://mydomain.com/functions/foo'); + }); + it('prefers emulator to custom domain', () => { const service = createTestService(app, 'https://mydomain.com'); connectFunctionsEmulator(service, 'localhost', 5005); diff --git a/packages/functions/src/service.ts b/packages/functions/src/service.ts index b70a5b1fe57..c5fe7fa8a85 100644 --- a/packages/functions/src/service.ts +++ b/packages/functions/src/service.ts @@ -122,7 +122,8 @@ export class FunctionsService implements _FirebaseService { // Resolve the region or custom domain overload by attempting to parse it. try { const url = new URL(regionOrCustomDomain); - this.customDomain = url.origin; + this.customDomain = + url.origin + (url.pathname === '/' ? '' : url.pathname); this.region = DEFAULT_REGION; } catch (e) { this.customDomain = null;