[英]firebase callable functions CORS/internal error
我在我的 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
我似乎無法獲得已部署的版本來調用這些函數。 在日志中,根本沒有調用函數。
有什么幫助嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.