从前端命中时,Firebase 模拟器云函数会抛出 cors 错误

Firebase emulator cloud function throws cors error when hit from frontend

我有这个功能,在生产中完美运行但是当 运行 在本地我得到 cors 错误

export const listUsers = functions.https.onRequest(async (req, res) => {
    res.set("Access-Control-Allow-Origin", "*")
    const data = await getSomeUsers(10)
    res.json(data)
})

模拟器启动正常:

cors 问题:

检查这个:

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).