【问题标题】:firebase cli serve cant access the project from different devicefirebase cli service 无法从不同的设备访问项目
【发布时间】:2018-07-23 23:06:05
【问题描述】:

我已经安装了 firebase cli 等。我可以启动项目并使用 firebase serve 进行开发。我可以通过 localhost:5000 访问该项目的页面,但是如果我尝试从网络中的不同设备(手机)访问 network-ip:5000,我会收到连接被拒绝。

有人知道转发端口 5000 需要什么配置/命令吗? (不同的项目,如 creat-react-app 工作正常)

【问题讨论】:

    标签: firebase firebase-cli


    【解决方案1】:

    使用本地 IP 192.168.0.10 我启动了firebase serve -o 192.168.0.10,它在其他设备的 5000 端口上完美运行

    在我的 javascript 应用程序中: functions.useFunctionsEmulator('http://192.168.0.10:5000')

    【讨论】:

      【解决方案2】:
      firebase serve -o 0.0.0.0
      

      -o 标志设置主机。

      欲了解更多信息,请参阅Server Fault: What's the difference between IP address 0.0.0.0 and 127.0.0.1?

      【讨论】:

        【解决方案3】:

        This 为我工作。我找到了函数模拟器的 config.json 文件(它在 mac 或 windows 上的 user/.config/configstore/@googlecloud/functions-emulator/config.json 中)并将“bindHost”:“localhost”更改为“bindHost” ": "0.0.0.0" 然后我可以通过 localip:5000 从我网络上的其他设备访问服务的功能,这在以前不起作用。

        Tivoli 于 2017 年 8 月 20 日发表评论•

        挖掘代码我发现了这一点,这是因为 firebase-tools 仅将 projectId 设置为 功能模拟器配置。这在我的 Dockerfile 中修复了它

        添加 config.json /root/.config/configstore/@google-cloud/functions-emulator/config.json

        config.json 看起来像这样

        {
        "bindHost": "0.0.0.0" }

        您可以将 0.0.0.0 更改为您想要的任何主机,但这适用于 码头工人。

        供参考 https://github.com/firebase/firebase-tools/blob/master/lib/serve/functions.js#L71 是有问题的块,它需要将上述参数设置为 与 --host 命令行参数相同。

        如果您在自己的本地机器上运行,那么您需要设置它 到 OS X 上您各自操作系统的 configstore 文件夹,它将是 ~/.config/configstore/@google-cloud/functions-emulator/config.json.

        默认配置值参考 https://github.com/GoogleCloudPlatform/cloud-functions-emulator/blob/master/src/defaults.json

        【讨论】:

          【解决方案4】:

          如果您运行firebase serve --help,它将为您提供侦听不同端口或 IP 地址所需的信息:

          Usage: serve [options]
          
          start a local server for your static assets
          
          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: functions, hosting)
          --except <targets>  serve all except specified targets (valid targets are: functions, hosting)
          -h, --help          output usage information
          

          您可以在命令行上使用 -p 和 -o 来更改它侦听连接的主机和端口。对于您的情况,您将无法使用 localhost 作为主机,因为这仅对同一台机器上的其他进程可见。

          【讨论】:

            猜你喜欢
            • 2020-04-04
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-10-27
            • 2022-12-01
            • 2019-02-19
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多