firebase cli serve 无法从不同的设备访问项目

firebase cli serve cant access the project from different device

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

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

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

This 对我有用。我找到了 functions-emulator 的 config.json 文件(它在 user/.config/configstore/@googlecloud/functions-emulator/config.json on mac or windows) 并将 "bindHost": "localhost", 更改为 "bindHost": "0.0.0.0" 然后我可以通过 localip:5000 从网络上的其他设备访问服务功能'以前工作过。

Tivoli commented on Aug 20, 2017 •

Digging around the code I figured this out, it's because the firebase-tools is only setting the projectId as part of the functions-emulator config. This fixes it in my Dockerfile

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

and the config.json looks like this

{
"bindHost": "0.0.0.0" }

You can change the 0.0.0.0 to any host you want, but this works for Docker.

For reference https://github.com/firebase/firebase-tools/blob/master/lib/serve/functions.js#L71 is the offending block, it needs to set the above parameter to the same as the --host command line parameter.

If you are running on your own local machine then you need to set it to the configstore folder for your respective OS on OS X it would be ~/.config/configstore/@google-cloud/functions-emulator/config.json.

Reference for the default config values https://github.com/GoogleCloudPlatform/cloud-functions-emulator/blob/master/src/defaults.json

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?

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

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