While emulating Hosting and Functions, requests to the home location don't trigger the corresponding Cloud Function
See original GitHub issue[REQUIRED] Environment info
Packages:
firebase-tools@7.7.0 (globally installed)
"firebase-functions": "^3.3.0", // FROM functions/package.json
Node version: v10.16.2 VSCode 1.32.3
firebase-tools: v7.7.0
Platform: Windows 10
[REQUIRED] Test case
firebase.json
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
],
"ignore": [
"functions/src/**"
]
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"function": "ssrLanding"
}
]
},
"storage": {
"rules": "storage.rules"
}
}
With the firebase.json
config above, I’m trying to rewrite routes to my home location (with or without trailing slash) to be handled by a cloud functions.
[REQUIRED] Steps to reproduce
Using the firebase.json
above.
Run firebase serve --only hosting,functions
Or firebase emulators:start --only hosting,functions
PS C:\myProject> firebase serve --only hosting,functions
i hosting: Serving hosting files from: public
+ hosting: Local server: http://localhost:5000
+ functions: Using node@10 from host.
+ functions: Emulator started at http://localhost:5001
i functions: Watching "C:\myProject\functions" for Cloud Functions...
+ functions[ssrLanding]: http function initialized (http://localhost:5001/myProject/us-central1/ssrLanding).
Everything starts OK, as we can see from the log above.
[REQUIRED] Expected behavior
I would request http://localhost:5000
or http://localhost:5000/
(with or without trailing slash) and the function ssrLanding
would handle the response.
Actually, with this configuration, any location should be handled by the function, right?
[REQUIRED] Actual behavior
When I request http://localhost:5000
or http://localhost:5000/
the server responds with the index.html
file which is in my public folder.
When I request http://localhost:5000/whatever
, the function is triggered and responds.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
@cbdeveloper thanks that’s good feedback! I’ll make sure your docs feedback bug gets to the right person and also link them to this explanation
Thanks! https://stackoverflow.com/questions/44925138/firebase-dynamic-hosting-rewrite-the-home-page https://stackoverflow.com/questions/53519531/how-to-change-firebase-homepage-destination/53520119#53520119
From these two SO questions and people’s comments on them, I think this might be causing a some confusion.
Priority order of Hosting responses
From what you’ve said, I guess that the homepage
'/'
route defaults toindex.html
and therefore it’s categorized as a number 3 from the list above, which is higher than “Configured Rewrites” for the'/'
homepage route.But I think the examples in the DOCs and also from the default configuration that
firebase-tools
sets when youinit
a project as a single page app, might cause this confusion.I think it would be useful to add to the DOCs (under the direct requests to a cloud function section), some note about rewriting the homepage
'/
’ route to a cloud function. I guess it would be nice to mention a recommended workaround.A recommended workaround would be to change the
index.html
name for something different, likeapp.html
? Is there any better option ?I know that serving
index.html
for the home route is standard default for HTTP servers, but I think it’s worth mentioning it explicitly. Otherwise it’s easy to forget.PS: I’ve also sent a feedback through the DOCs website.