我已经安装了firebase cli etcetc。我可以启动项目并使用firebase服务进行开发。我可以通过localhost:5000访问项目的页面,但如果我尝试从我的网络(手机)中的不同设备访问network-ip:5000,我会拒绝连接。
任何人都知道转发端口5000需要什么配置/命令? (像creat-react-app这样的不同项目工作正常)
答案 0 :(得分:5)
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?
答案 1 :(得分:0)
如果您运行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作为主机,因为它只对同一台计算机上的其他进程可见。
答案 2 :(得分:0)
This为我工作。我找到了函数模拟器的config.json文件(它在mac或windows上的user/.config/configstore/@googlecloud/functions-emulator/config.json中)并更改了#34; bindHost&#34 ;:&#34; localhost&#34;,to&#34; bindHost&#34;:&#34; 0.0.0.0&#34;然后我可以通过localip:5000访问我网络上其他设备提供的服务功能。之前没有工作过。
Tivoli于2017年8月20日发表评论•
挖掘代码我想出来了,这是因为 firebase-tools只将projectId设置为 函数 - 模拟器配置。这修复了我的Dockerfile
ADD config.json /root/.config/configstore/@google-cloud/functions-emulator/config.json
,config.json看起来像这样
{
&#34; bindHost&#34;:&#34; 0.0.0.0&#34; }您可以将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
答案 3 :(得分:0)
使用本地IP 192.168.0.10
我启动了firebase serve -o 192.168.0.10
,它可以在其他设备的端口5000上完美运行
在我的javascript应用程序中: functions.useFunctionsEmulator('http://192.168.0.10:5000')