-
Notifications
You must be signed in to change notification settings - Fork 900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP functions path prefix differences between emulated and deployed functions #1312
Comments
Thanks for this thorough bug. This will require a bit of a discussion to figure out the best route forward. I'll speak with the other emulator engineers next week and see if we can decide how to move forward. |
The fix for #1279 in release 6.10.0 solved my immediate problem, but it would be great to be able to have access to the mount point of the functions. If deployed firebase functions will always have their own subdomain and no extra path prefix If there is any possibility that deployed functions might have a different path prefix in some future firebase release, Perhaps the express app that invokes the request, could be a sub-app that is mounted at the prefix point. Then the prefix path would be available as expected by express handlers in req.app.mountpath (The |
Fix has been merged into |
@abeisgoat Has this been resolved? For me, |
@liezl200 there are two parts:
Can you explain a little more about your use case? Ideally by filing a new issue since discussing on a closed issue is easy to miss. |
@samtstern Ahh, thanks for the response. I thought that path prefix on localhost was removed for Firebase functions when using the emulator. It works as you describe. My use case is: I want to build a redirect URI for a button based on my current host (to automatically handle production vs development). The button href uses an external API that I don't have control over, which requires me to pass the redirect_uri as a query parameter. I use express routing, so I have a route In development, I can't just have my frontend HTML pass "localhost:5001/redirect" as redirect_uri, it has to use "localhost:5001/path/prefix/redirect". In production I need to use "firebase.app/redirect". It's easy enough to use an environment variable to handle production vs. development environments but it does add some extra complexity in my frontend code. Anyway, since you say it's expected, no need to open a new issue. |
@liezl200 thanks that makes sense! I think we should be able to make this work more seamlessly, but I will have to investigate. I am somewhat terrible at express :-) PRs always welcome if you think you know the fix! But emulators code is fairly complex so I probably have to do this one myself (or @abeisgoat might know what to do) |
So this was never fixed and the problem is exacerbated in Functions V2. Currently, when you deploy a function your url looks like this: https://functionname-leffhkkdww-uc.a.run.app When you check the function in Google Cloud Console, it looks like this: https://us-central1-project-name-123ab.cloudfunctions.net/functionName And when you deploy with the emulator, it looks like this: http://127.0.0.1:5001/project-name-123ab/us-central1/functionName So to work around this my team and I have to write a layer on top of firebase and maintain it as Firebase gets worse and worse to use. This bug was never solved. |
Agreed, this is not ideal. And for some reason, in my case, Firebase isn't loading a .env file so I have to make the reconciliation directly in the code instead of using a config file. |
For Posterity
This stems from a conversation #1279
@christiannaths commented
@abeisgoat commented
[REQUIRED] Environment info
firebase-tools: 6.9.2
Platform: macOS
[REQUIRED] Test case
Public repo: https://github.com/christiannaths/fbfn-path-prefix-example
Deployed function: https://us-central1-christiannaths-com.cloudfunctions.net/fnEcho
[REQUIRED] Steps to reproduce
Run above test function in a new project, once locally in the emulator, and once deployed. Observe the response from each scenario. (see Actual behavior below for a sample)
[REQUIRED] Expected behavior
I expect the paths to be exactly the same in the emulator as they are once deployed, or at least be able to reason about the differences.
I see three ways to solve this:
To be perfectly honest, I strongly feel that having a prefix in the emulator at all is unexpected behavior, though I do understand the behaviour exists for legacy support.
As a suggestion, perhaps the newer
firebase emulators:start
could serve the functions without the prefix, and legacy behaviour could be supported withfirebase serve
.[REQUIRED] Actual behavior
Emulated
response
Deployed
response
The text was updated successfully, but these errors were encountered: