0

I'm trying to get every url in a subdomain to be routed through a firebase function. This is my configuration:

The functions file:

const functions = require('firebase-functions');

exports.handleWebRequest = functions
  .region('europe-west1')
  .https
  .onRequest((req, res) => {
    res.send('Currently down.');
  });

My firebase.json:

{
  "hosting": {
    "public": "dist",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "function": "handleWebRequest"
      }
    ]
  },
  "functions": {
    "source": "firebase-functions",
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint"
    ]
  }
}

When I deploy the hosting and functions, and go to the URL in my browser, I expect to see "Currently down" for every route I open. However, every route except the root route shows the "Currently down" message, and the root route shows the index.html that I deployed.

So, in a nutshell:

/ shows my index.html (which I don't want)
/whatever shows "Currently down." (which is what I want)

The reason I'm trying to route everything through the function, is because I want to shield the website with HTTP Basic Auth, which is "not natively supported" by Firebase.

2 Answers 2

3

This is most probably because you still have the index.html file under the public folder.

As explained in the doc:

Note: The static files in the public directory take precedence over the rewrites, so any static files will be served alongside the Cloud Functions endpoints.

If you remove the index.html file it should work the way you expect.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, will accept your answer or the other one depending on what we decide to use.
3

Your function is deployed to the "europe-west1" region, but Firebase Hosting currently only supports the default "us-central1". This is stated in the documentation:

Important: Firebase Hosting supports Cloud Functions in us-central1 only.

2 Comments

Thank you. Is it possible to just host the function in europe-west1, including the website's HTML + assets? Would this be more expensive / less performant?
It's not clear to me what you're proposing. Perhaps you could give it a try, and post another question if you get stuck with that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.