Firebase Callable Function + CORS

后端 未结 9 1241
Happy的楠姐
Happy的楠姐 2020-12-15 04:52

I\'m trying to call a callable Cloud Function from my app, but I\'m facing CORS issues.

I can\'t enable Cors since I don\'t have access to the request and response

相关标签:
9条回答
  • 2020-12-15 05:31

    I had this problem with some of my Firebase functions but not others. I eventually fixed it by doing this:

    1. Commenting the function out in index.js
    2. Running firebase deploy
    3. Entering y at the prompt to delete the function
    4. Waiting for 5 to 10 minutes
    5. Removing the comments around the function and running firebase deploy again

    Without any changes to the function itself, it now runs without any CORS issues.

    0 讨论(0)
  • 2020-12-15 05:44

    Probably many will hit this issue with the emulator and cors messages.

    I havn't seen my case discussed in any discussion I've seen in Google, I do have seen many "can't reproduce", maybe my case will shade some light:

    In my case the issue was that I wasn't running the hosting from the firebase emulator.

    When you run your react app via npm start - while the functions run via firebase emulators:start, you will see the Cors errors.

    So when testing cloud function calls, rather using npm start, you should do npm run build and then access the app from the emulator...

    Search for something like: "hosting: Local server: http://localhost:5000"

    few notes -

    • Your functions should also work against the emulator via

      const functions = firebaseApp.functions('europe-west3');// lets assume thats your region functions.useFunctionsEmulator('http://localhost:5000');

    0 讨论(0)
  • If none of the above is helping: In my case the reason was that I havent correctly set up my regions. This can especially happen when using 3rd party libraries.

    0 讨论(0)
提交回复
热议问题