簡體   English   中英

使用安全連接 (HTTPS) 在本地運行 Firebase 函數

[英]Running Firebase Functions locally with secure connections (HTTPS)

我有一個使用 HTTPS 提供的 React 應用程序(我需要它用於在后台運行的服務工作者),它在我的后端使用 Firebase 函數在本地運行時存在 CORS 問題。

Firebase Functions 只是包裝了一個啟用了 CORS 模塊的 express 應用程序。 我對這個后端的 OPTIONS 調用執行了一些測試,我得到了正確的標頭。

他們的問題是我的前端 (HTTPS) 無法連接到我的后端 (HTTP)。 有沒有辦法使用 HTTPS 而不是 HTTP 在本地運行 Firebase 功能?

運行firebase serve --help僅顯示

Options:
  -p, --port <port>   the port on which to listen (default: 5000) (default: 5000)
  -o, --host <host>   the host on which to listen (default: localhost) (default: "localhost")
  --only <targets>    only serve specified targets (valid targets are: hosting, functions, database, firestore)
  --except <targets>  serve all except specified targets (valid targets are: hosting, functions)
  -h, --help          output usage information

本地模擬器目前不支持 HTTPS。 T 這里是 GitHub 上關於此的主題,建議將ngrok用於類似用例。 https://github.com/firebase/firebase-tools/issues

您可以使用本機反應腳本來做到這一點:

REACT_APP_ENV=development yarn start

包.json:

  "scripts": {
    "start": "HTTPS=true sh -ac '. .env.${REACT_APP_ENV}; react-scripts start'",
    ...

請參閱create-react-app文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM