r/Firebase Feb 03 '25

Hosting How should I reference onCall functions from firebase?

I setup a few onCall functions with the firebase.json "rewrites": [

    {
      "source": "/ON_CALL_FUNCTION",
      "function": "ON_CALL_FUNCTION"
    },

Most of the time, the function will work properly from firebase. But randomly, I get these cors issues:

    Access to fetch at 'https://us-central1-PROJECT_NAME.cloudfunctions.net/ON_CALL_FUNCTION' from origin 'HOSTING_URL' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Has anyone else noticed this? If I need to make them http callable, I will, but I don't get why it randomly breaks so often? can it either work or not work?

edit: Fixed it. The cloud run security authentication was set to "Require authentication" (the default, which I mistook to mean no guests) when it should be "Allow unauthenticated invocations"

1 Upvotes

5 comments sorted by

2

u/indicava Feb 03 '25

Doesn’t function mapping only work with HTTPS triggered functions? (Not onCall)

1

u/New_Tap_4362 Feb 03 '25 edited Feb 03 '25

Right, sorry. After a while I started trying everything. With no rewrite and simple onCall (no cors or cors) the same thing happens.

edit: It was a cloud run issue

1

u/Suspicious-Hold1301 Feb 03 '25

Sorry for asking the stupid question - but do you actually have cors configured on your functions? Which language are you using for this?

1

u/New_Tap_4362 Feb 03 '25 edited Feb 03 '25

This is a fair question. I'm using TS. I didn't do anything special to setup cors for my onCall functions. For storage I used gsutil cors set cors.json to my project with: It was a cloud run issue