admin管理员组

文章数量:1279124

I have a Firebase Callable Cloud Function which I call in my javascript app in the browser.

Because the request host is ...cloudfunctions and not my app domain this results in a CORS preflight OPTIONS request before the real POST request.

If this was a function with http trigger I'd avoid the extra time that the preflight takes by specifying my function as a rewrite in my hosting config and sending the request to the same domain my app is hosted on.

Is there any way to avoid this preflight with Firebase Callable Cloud Functions? Perhaps there's a way to proxy the request through Firebase Hosting, like you can with http Cloud Functions

I have a Firebase Callable Cloud Function which I call in my javascript app in the browser.

Because the request host is ...cloudfunctions and not my app domain this results in a CORS preflight OPTIONS request before the real POST request.

If this was a function with http trigger I'd avoid the extra time that the preflight takes by specifying my function as a rewrite in my hosting config and sending the request to the same domain my app is hosted on.

Is there any way to avoid this preflight with Firebase Callable Cloud Functions? Perhaps there's a way to proxy the request through Firebase Hosting, like you can with http Cloud Functions

Share Improve this question edited Mar 26, 2019 at 9:17 Jake asked Mar 26, 2019 at 8:32 JakeJake 13.2k19 gold badges70 silver badges97 bronze badges 5
  • "Normally I'd avoid the extra time that the preflight takes by specifying my function as a rewrite in my hosting config and sending the request to the same domain my app is hosted on." -> So why not this time? – Daniel Hilgarth Commented Mar 26, 2019 at 8:34
  • 2 That works for functions.https.onRequest because I can specify the host. This question is about Firebase Callable Cloud Functions – Jake Commented Mar 26, 2019 at 9:12
  • 2 Why the downvotes? – Jake Commented Mar 26, 2019 at 9:18
  • 2 I didn't downvote – Daniel Hilgarth Commented Mar 26, 2019 at 9:45
  • Make sure the function name referenced in the client is correct, see stackoverflow./a/62042554/1030246 – tazmaniax Commented May 14, 2021 at 15:37
Add a ment  | 

5 Answers 5

Reset to default 9

After bing through Firebase docs and JS SDK source I've decided this is not possible without using/overriding private APIs.

The solution I've used is to replicate the JS SDK code but specifying a URL that goes via Firebase Hosting so it's on the same domain as my app.

Same Cloud Function, same app code, no CORS preflight

本文标签: javascriptAvoid CORS preflight for Firebase callable functionStack Overflow