Skip to content

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

Draft
demolaf wants to merge 6 commits into
mainfrom
fix/hosting-rewrite-emulator-path
Draft

fix: correct path routing for Firebase Hosting rewrites in emulator#200
demolaf wants to merge 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 Outdated
Comment thread lib/src/server.dart Outdated
Comment thread lib/src/server.dart Outdated
Comment thread test/unit/server_test.dart Outdated
@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.

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.

1 participant