【问题标题】:Running Firebase Functions locally with secure connections (HTTPS)使用安全连接 (HTTPS) 在本地运行 Firebase 函数
【发布时间】:2020-05-25 01:16:16
【问题描述】:

我有一个使用 HTTPS 服务的 React 应用程序(我需要它用于在后台运行的服务人员) 我的后端使用 Firebase Functions 在本地运行时出现 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

【问题讨论】:

    标签: node.js firebase express google-cloud-functions firebase-cli


    【解决方案1】:

    本地模拟器目前不支持 HTTPS。这里是 GitHub 上的一个线程,建议使用 ngrok 来处理类似的用例。 https://github.com/firebase/firebase-tools/issues

    【讨论】:

      【解决方案2】:

      您可以使用本机反应脚本来做到这一点:

      REACT_APP_ENV=development yarn start
      

      package.json:

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

      参见create-react-app docs。

      【讨论】:

        猜你喜欢
        • 2018-10-10
        • 2013-03-09
        • 1970-01-01
        • 2021-10-09
        • 2022-01-17
        • 2017-11-27
        • 2013-02-28
        • 2013-05-01
        • 2013-02-13
        相关资源
        最近更新 更多