0
votes

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
Can you share the code of your Cloud Function pls? - Renaud Tarnec
@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. - Jeffrey Chen

2 Answers

2
votes

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.

1
votes

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.