Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
78 views
in Technique[技术] by (71.8m points)

json-server cannot access via local IP

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 reinstalled it and now I can do requests only to localhost or 127.0.0.1. Can't do requests to local IP (cmd ipconfig) anymore. I'm getting this error:

enter image description here

As @fvu mentioned here

this means that the server software is configured to listen on the localhost interface only. This is a configuration item and to avoid exposing a potentially unsecure server many server programs come preconfigured to listen on localhost only.

So is there a way to access this server via local IP as long as json-server doesn't have some extra parameters to enable/disable it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found the solution for this issue:

json-server --host 192.168.1.XXX my_file.json

Using this command, server is deployed on my local IP, and Windows asks for a firewall exception.

Another solution is to switch to .NET server - another free simple fake server where I can setup local IP as endpoint.

All it needs to:

  1. install .NET
  2. use CMD commands:

       git clone https://github.com/ttu/dotnet-fake-json-server.git
       cd dotnet-fake-json-server/FakeServer
       dotnet run [--file] [--urls]
    
        #like so in my case:
        dotnet run --file_data.json --urls http://192.168.1.192:57602
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...