firebase cli serve cant access the project from different device

一笑奈何 提交于 2019-12-01 05:16:59

问题


I have install firebase cli etcetc. I can start the project and develop using firebase serve. I can visit the page of the project through localhost:5000 but if i try from different device in my network (mobile phone) to access network-ip:5000 I get connection refused.

Anyone knows what configuration/command it needs to forward port 5000 ? (different projects like creat-react-app works fine)


回答1:


firebase serve -o 0.0.0.0

The -o flag sets the host.

For more information, see Server Fault: What's the difference between IP address 0.0.0.0 and 127.0.0.1?




回答2:


If you run firebase serve --help, it will give you the information needed to listen on a different port or IP address:

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

You can use -p and -o on the command line to change the host and port where it listens for connections. For your case, you won't be able use localhost for the host because that's only visible to other processes on the same machine.




回答3:


This worked for me. I found the config.json file for the functions-emulator (It's in user/.config/configstore/@googlecloud/functions-emulator/config.json on mac or windows) and changed "bindHost": "localhost", to "bindHost": "0.0.0.0" and then I could access served functions from other devices on my network via localip:5000 which wasn't working before.

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



来源:https://stackoverflow.com/questions/48769168/firebase-cli-serve-cant-access-the-project-from-different-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!