![](/img/trans.png)
[英]When calling Firebase cloud function locally I receive a 200 response but the response is a cors type response not my actual data
[英]500 error response to CORS preflight OPTIONS when calling cloud function. How can I call a cloud function from my web-app and be CORS compliant?
我正在嘗試將雲功能合並到我的網絡應用程序中。 不幸的是,我遇到了難以處理的 CORS 錯誤。 似乎幾乎所有關於 CORS 的文檔都在使用 XMLHTTPRequests,有些正在使用 fetch api,但我找不到有關如何使用firebase.functions.httpsCallabe()
執行此操作的任何信息
客戶端代碼:
export function bla() {
const callable = firebase.functions().httpsCallable('helloWorld');
return callable().then(console.log);
}
整個雲功能(在打字稿中):
import * as functions from 'firebase-functions';
const cors = require('cors')({ origin: true });
export const helloWorld = functions.https.onRequest((request, response) => {
cors(request, response, () => {
response.status(200).send("Hello from Firebase!");
});
});
這是 chrome 控制台在觸發我的bla()
函數時輸出的內容:
在 Firebase 控制台中,我收到一條消息,指出我正在使用標准計划,因此無法訪問外部資源。 不確定這是標准消息還是我的代碼的實際問題。
您不能使用 Functions 客戶端 SDK 來調用HTTP 類型的函數。 您只能使用 Functions 客戶端 SDK 來調用在鏈接文檔中看到的聲明的可調用類型函數。
可調用函數使用functions.https.onCall
聲明,而 HTTP 函數使用functions.https.onRequest
聲明。
如果你想調用一個普通的 HTTP 類型函數,你應該使用一些 HTTP 客戶端。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.