【发布时间】:2020-05-13 10:22:44
【问题描述】:
我在我的 firebase api 中集成了可调用函数,并在客户端做出反应。我正在使用 firebase 模拟器来模拟可调用函数,以便在 localhost:5000 进行本地测试。在本地调用模拟函数时,它们可以正常工作,但是在部署时返回错误。
这是我的客户电话:
let functions = firebase.app().functions('europe-west2');
if (process.env.NODE_ENV === 'development') {
functions.useFunctionsEmulator(process.env.REACT_APP_FIREBASE_CALLABLE);
}
export const listTrainers = () => async dispatch => {
try {
let listTrainersFunction = functions.httpsCallable('listTrainers');
let request = await listTrainersFunction();
}
}
我的 REACT_APP_FIREBASE_CALLABLE 在本地设置为http://localhost:5001,部署时不使用。
我的 firebase 模拟器正在运行,它在本地模拟我的功能:
functions[listTrainers]: http function initialized (http://localhost:5001/app-name/europe-west2/listTrainers).
这非常有效,所有数据都按预期检索。 但是,当我部署我的函数并尝试在生产中从我的客户端执行可调用函数时,我收到以下错误:
Access to fetch at 'https://europe-west2-app-name.cloudfunctions.net/app-name/europe-west2/listTrainers' from origin 'https://app-name.herokuapp.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
index.cjs.js:604 POST https://europe-west2-app-name.cloudfunctions.net/app-name/europe-west2/listTrainers net::ERR_FAILED
在我的 firebase 仪表板上,功能如下:
https://europe-west2-app-name.cloudfunctions.net/listTrainers
我似乎无法让部署的版本调用这些函数。在日志中,根本没有调用函数。
有什么帮助吗?
【问题讨论】:
标签: javascript firebase google-cloud-functions