Last active
April 14, 2023 08:56
-
-
Save mediavrog/49c4f809dffea4e00738a7f5e3bbfa59 to your computer and use it in GitHub Desktop.
CORS in Google Cloud Functions for Firebase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cors = require('cors')({origin: true}); | |
exports.sample = functions.https.onRequest((req, res) => { | |
cors(req, res, () => { | |
res.send('Passed.'); | |
}); | |
}); |
@jpfong I want to thank you for your post I have been spending the last 4 hours trying to get cors working. So random why would they not put an example in the docs. Thank you so much
Hello, Im getting the cors error and I can figure out why, here is may code:
import express from "express";
import cors from "cors";
const expressApp = express();
expressApp.use(cors({origin: true}));
expressApp.get("/Hello", (req, res) => {
res.send("Hello!");
});
Can anyone help me out?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jesster2k10 Your answer seems great, but passing the regions with the spread operator gives an typescript error.
Argument of type 'string' is not assignable to parameter of type '"europe-west2" | "europe-west3" | "us-central1" | "us-east1" | "us-east4" | "europe-west1" | "asia-east2" | "asia-northeast1"'.ts(2345)
.Do you know how to fix this? For now I'm sticking to one region to overcome this problem.
Thanks for the great answer.