Skip to content

fix: correct path routing for Firebase Hosting rewrites in emulator - #200

Merged
demolaf merged 6 commits into
mainfrom
fix/hosting-rewrite-emulator-path
Jun 22, 2026
Merged

demolaf merged 6 commits into
mainfrom
fix/hosting-rewrite-emulator-path

Conversation

@demolaf

@demolaf demolaf commented Jun 2, 2026 •

Copy link
Copy Markdown
Member

Fixes #175

Fixes request path handling for Firebase Hosting rewrites in the emulator: the old heuristic guessed the function name from segment count, causing handlers to receive the emulator's routing prefix instead of the original client path.

The new routing logic matches registered function names directly against path segments and reconstructs the request with the correct path before dispatching.

Adds unit tests, E2E tests via a new echoPath fixture, and a minimal hosting example.

Dependent on firebase/firebase-tools#10588

@demolaf
demolaf marked this pull request as draft June 2, 2026 15:32
@demolaf demolaf linked an issue Jun 2, 2026 that may be closed by this pull request

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a Firebase Hosting rewrites example and updates the path-based routing logic in the local server to correctly handle hosting rewrites and direct emulator calls. The review feedback highlights several critical bugs in the path parsing and prefix-stripping logic, particularly when handling deep sub-paths (e.g., /echo/deep/path), which can lead to incorrect function name extraction or lost sub-paths. The reviewer suggests refactoring the routing to match segments against registered function names and using the resolved function name to robustly strip prefixes, alongside adding test coverage for deep sub-paths.

Comment thread lib/src/server.dart Resolved
Comment thread lib/src/server.dart Resolved
Comment thread lib/src/server.dart Resolved
Comment thread test/unit/server_test.dart Resolved
@demolaf

demolaf commented Jun 15, 2026 •

Copy link
Copy Markdown
Member Author

CI should pass as soon as this PR firebase/firebase-tools#10588 is shipped in the next firebase-tools release.

@demolaf
demolaf force-pushed the fix/hosting-rewrite-emulator-path branch from 916b51f to 4b4ab54 Compare June 22, 2026 08:50
@demolaf
demolaf marked this pull request as ready for review June 22, 2026 08:51
@demolaf
demolaf requested a review from Lyokone June 22, 2026 09:02
@demolaf
demolaf merged commit 667795a into main Jun 22, 2026
18 checks passed
@demolaf
demolaf deleted the fix/hosting-rewrite-emulator-path branch June 22, 2026 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emulator doesn't correctly handle hosting rewrites.

2 participants