Setting up a firestore functions.https.onRequest, calling this on my frontend errors No 'Access-Control-Allow-Origin' header is present on the requested resource.
Tried a lot of other answers but could not get it to work. how do I set cors up properly for google cloud functions?
I tried most of the answers on stackoverflow the past 3 hours.
Adding the cors header to the bucket via gsutil (from this answer https://stackoverflow.com/a/37765371/7151828), ? Don't know if that is something else, though...
I tried to do it like this function sample: https://github.com/firebase/functions-samples/blob/master/quickstarts/time-server/functions/index.js
This is my attempt using cors middleware
const functions = require('firebase-functions');
const cors = require('cors')({
origin: true
});
const admin = require('firebase-admin');
admin.initializeApp();
exports.exampleFunction = functions.https.onRequest(async (req, res) => {
return cors(req, res, () => {
// Forbidding PUT requests.
if (req.method === 'PUT') {
return res.status(403).send('Forbidden!');
}
//respond to CORS preflight requests
if (req.method == 'OPTIONS') {
res.status(204).send('');
return null
}
// code ...
res.sendStatus(200);
}
I dont know what I am doing wrong.
What am I doing wrong here?