I am unable to make calls to cloud functions from the browser because of Cors. There is nowhere in the documentation that talks about options for disabling it. Is it even possible? If not, why is it one of the basic examples of firebase web apps?
code:
firebase
.functions()
.httpsCallable("helloWorld")()
.then(() => {});
The code on server side shouldn't matter since it's a client-side issue of disabling the CORS policy. Is it even possible?
The error:
Access to fetch at 'https://us-central1-projectepic-adcf9.cloudfunctions.net/helloWorld' from origin 'https://projectepic-adcf9.web.app' has been blocked by CORS policy
There are similar questions out there but they all provide solutions that don't work.
Server side code:
const { onRequest } = require("firebase-functions/v2/https");
const logger = require("firebase-functions/logger");
const cors = require("cors")({ origin: true });
// Create and deploy your first functions
// https://firebase.google.com/docs/functions/get-started
exports.helloWorld = onRequest((request, response) => {
cors(req, res, () => {
logger.info("Hello logs!", { structuredData: true });
res.set("Access-Control-Allow-Origin", "*");
res.send("Hello from Firebase!");
});
});