Firebase emulator cloud function throws cors error when hit from frontend

僤鯓⒐⒋嵵緔 提交于 2021-02-11 13:36:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!