问题
I have this function that works perfectly in production however when running locally I get cors errors
export const listUsers = functions.https.onRequest(async (req, res) => {
res.set("Access-Control-Allow-Origin", "*")
const data = await getSomeUsers(10)
res.json(data)
})
emulators starts fine:
cors issue:
回答1:
Check this:
Deadly CORS when http://localhost is the origin
Chrome does not support localhost for CORS requests (a bug opened in 2010, marked WontFix in 2014).
To get around this you can use a domain like lvh.me (which points at 127.0.0.1 just like localhost) or start chrome with the --disable-web-security flag (assuming you're just testing).
来源:https://stackoverflow.com/questions/62438960/firebase-emulator-cloud-function-throws-cors-error-when-hit-from-frontend