Skip to content

Commit

Permalink
Allow a custom path in Firebase functions custom domain (#8441)
Browse files Browse the repository at this point in the history
* 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 <dlarocque@google.com>

---------

Co-authored-by: Daniel La Rocque <dlarocque@google.com>
  • Loading branch information
segevfiner and dlarocque authored Aug 19, 2024
1 parent 05c34c9 commit 2ee2a90
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/dull-nails-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/functions': patch
---

Allow a custom path in Firebase functions custom domain
5 changes: 5 additions & 0 deletions packages/functions/src/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion packages/functions/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2ee2a90

Please sign in to comment.