question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
samtsterncommented, Nov 12, 2019

@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

0reactions
cbdevelopercommented, Nov 12, 2019

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

1. Reserved namespaces that begin with a /__/* path segment
2. Configured redirects
3. Exact-match static content
4. Configured rewrites
5. Custom 404 page
6. Default 404 page

From what you’ve said, I guess that the homepage '/' route defaults to index.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 you init a project as a single page app, might cause this confusion.

{
    "source": "**",
    "destination": "/index.html"
  }

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, like app.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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cloud Functions triggers - Google Cloud
You can set up Cloud Functions to execute in response to various scenarios by specifying a trigger for your function. Triggers can be...
Read more >
Run functions locally | Cloud Functions for Firebase - Google
The emulators:start command will start emulators for Cloud Functions, Cloud Firestore, Realtime Database, and Firebase Hosting based on the products you ...
Read more >
Enabling CORS in Cloud Functions for Firebase
When I check the Firebase Console function log, it says access to external network resources not allowed if the billing account is not...
Read more >
HTTP Google Cloud Functions in Python
There is no assumed knowledge about Cloud Functions. What you will build. In this codelab, you will publish a Cloud Function that, when...
Read more >
Local fulfillment | Cloud-to-cloud - Google Home Developers
In production, Google hosts your app in a secure JavaScript sandbox environment on the user's Google Home or Google Nest device. The Report ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found