2

I want to rewrites all URL end with "api/(funcName)" to call cloud function (funcName).

In firebase.json I set rewrites rules as follows.

"rewrites": [
  {
    "source": "api/:funcName",
    "function": ":funcName"
  },
  {
    "source": "**",
    "destination": "/index.html"
  }
] 

but it's not working.

I got

Error: Forbidden

Your client does not have permission to get URL /:funcName/api/(funcName) from this server.

(funcName) is the real function name I don't want to show here.

2
  • 1
    Can you share the code of your Cloud Function pls? Commented Oct 13, 2019 at 12:01
  • @RenaudTarnec The function works fine if I type the real function name instead of :funcName, there is nothing to do with the function itself. Just I don't want to set 100 rewrite entries if I have 100 functions, so I'm looking for some easy ways like the code I proposed, which doesn't work. Commented Oct 13, 2019 at 12:47

2 Answers 2

3

Your rewrite should include the exact name of the function. The rewrite system doesn't support named wildcard routes like you use in Express. If you want to wildcard all URLs with a prefix, use the glob syntax supported by Firebase Hosting as described in the documentation.

  {
    "source": "api/**",
    "function": "funcName"
  },

Where "funcName" is the name of your function as exported by your code.

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

1 Comment

It seems that the hosting emulator(firebase-tools 10) only rewrites with ** as source. Although this api/** looks convenient, but it is unfortunately not working giving a 404 for /api.
1

I'm not exactly sure how you got it to throw that error message, but from what I can quickly see the error message comes from Cloud Functions, or from something between Firebase Hosting and your Cloud Function.

Given where the error message comes from, Firebase Hosting won't be able to hide it for the response.

Comments

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.