14

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

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

4

4 回答 4

29
firebase serve -o 0.0.0.0

-o标志设置主机。

有关详细信息,请参阅服务器故障:IP 地址 0.0.0.0 和 127.0.0.1 之间有什么区别?

于 2018-12-02T21:16:00.587 回答
1

如果您运行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 作为主机,因为这仅对同一台机器上的其他进程可见。

于 2018-02-13T16:42:20.693 回答
1

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

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

于 2020-10-21T08:24:37.577 回答
0

对我有用。我找到了函数模拟器的 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 日发表评论•</p>

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

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

config.json 看起来像这样

{
“绑定主机”:“0.0.0.0”}

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

供参考 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

于 2018-03-19T06:22:47.497 回答