json-server cannot access via local IP

前端 未结 5 1094
盖世英雄少女心
盖世英雄少女心 2020-12-13 20:31

I\'m using npm json-server from here. It used to work great for my needs: run a server on my PC and do GET requests to local IP (192.168.1.XX). I r

5条回答
  •  被撕碎了的回忆
    2020-12-13 21:06

    Localhost if you will use the same device:

    json-server --watch filename.json

    the localhost IP is 127.0.0.1 so, you can access this filename.json by 2 ways, either by

    1. http://localhost:8000/filename.json
    2. http://127.0.0.1:8000/filename.json

    In case you want to access the localhost from another computer/mobile device, place the IPV4 address of your computer

    json-server --host 192.168.0.xx file.json

    You can also assign a port number of your own using this command:

    json-server --host 192.168.0.xx file.json --port 4000

    then run it on any device connected with the same network using

    1. http://192.168.0.xx:4000/file.json

    Finally if you did not understood where did i take this host IP from, Go to command prompt > config /all and look for IPv4 address, copy paste that address to this URL, remember that devices should be on the same network to access this IP.

提交回复
热议问题