firebase cli serve cant access the project from different device

后端 未结 4 1883
醉酒成梦
醉酒成梦 2021-01-11 13:55

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 di

相关标签:
4条回答
  • 2021-01-11 14:25
    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?

    0 讨论(0)
  • 2021-01-11 14:33

    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.

    0 讨论(0)
  • 2021-01-11 14:42

    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

    0 讨论(0)
  • 2021-01-11 14:44

    With a local IP 192.168.0.10 I launched firebase serve -o 192.168.0.10 and it works perfectly on port 5000 from other device

    In my javascript app : functions.useFunctionsEmulator('http://192.168.0.10:5000')

    0 讨论(0)
提交回复
热议问题