Fix/apphosting port validation#9937
Conversation
Summary of ChangesHello @jayeshpandey01, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the App Hosting emulator's flexibility by relaxing its port validation rules for custom start commands. Previously, the emulator would reject any command containing explicit port flags, hindering various development setups. The changes now allow users to specify ports in their commands while intelligently handling Angular CLI-specific port requirements and providing helpful warnings for potential port mismatches, ultimately improving the developer experience without introducing breaking changes. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses the overly restrictive port validation in the App Hosting emulator by removing the error and implementing a more flexible warning system for port mismatches. The changes are logical and well-implemented. I've included a few suggestions to enhance the robustness of the port detection logic and to make the associated tests more comprehensive by asserting the new warning behavior.
|
Why is the existing emulator port configuration via firebase.json not sufficient in these cases? https://firebase.google.com/docs/emulator-suite/install_and_configure#port_configuration |
The In many real-world setups, the start command invokes a framework dev server (e.g.
For example, Angular CLI does not reliably respect the The previous validation blocked legitimate use cases by rejecting any command containing
This approach keeps the emulator configuration authoritative while allowing flexibility for framework-specific requirements and custom workflows. |
|
Thanks for the question! The In many cases—especially for Angular apps—framework tools do not reliably respect the So:
This approach aligns with the documented guidance for Angular and other frameworks where the start command may need explicit port configuration, and ensures both the emulator and the framework dev server are correctly aligned without restrictive errors. :contentReference[oaicite:1]{index=1} |
Fix: Remove restrictive port validation in App Hosting custom start commands
Problem
The App Hosting emulator enforced overly restrictive validation that rejected any custom start command containing
--portor-pflags. This validation threw aFirebaseErrorand prevented legitimate use cases where developers need explicit port control in their custom commands.Previous behavior:
This blanket rejection was problematic for:
Solution
This PR refactors the port handling logic to be more permissive while maintaining intelligent defaults:
1. Removed Restrictive Validation
Eliminated the error-throwing validation that blocked port flags entirely.
2. Conditional Port Injection for Angular CLI
Angular CLI doesn't respect the
PORTenvironment variable, so we conditionally append--portonly when not already present:3. Port Mismatch Detection & Warning
Added regex-based port extraction to detect user-specified ports and warn on mismatches:
Technical Changes
Modified Files:
src/emulator/apphosting/serve.ts- Core port handling logicsrc/emulator/apphosting/serve.spec.ts- Updated test suiteKey Improvements:
/--port[= ](\d+)|-p[= ](\d+)/Testing
Updated test suite to validate new behavior:
Test Coverage:
--portinjectionBreaking Changes
None. This change is backward compatible and makes the emulator more permissive.
Related Issues
Fixes issues where developers using custom start commands with port specifications were blocked by the emulator.