json-server无法通过本地IP访问 [英] json-server cannot access via local IP
问题描述
我在
As @fvu提到这里
这意味着服务器软件配置为仅侦听localhost接口。这是一个配置项,为了避免暴露可能不安全的服务器,许多服务器程序预先配置为仅在localhost上侦听。
那么是只要json-server没有一些额外的参数来启用/禁用它,就可以通过本地IP访问这个服务器吗?
我找到了解决此问题的方法:
json-server --host 192.168.1.XXX my_file.json
使用此命令,服务器部署在我的本地IP上,Windows要求防火墙例外。
切换到的另一种解决方案。 NET服务器 - 另一个免费的简单虚假服务器,我可以将本地IP设置为端点。
所有它需要:
- 安装.NET
-
使用CMD命令:
git clone https://github.com/ttu/dotnet-fake-json-server.git
cd dotnet-fake-json-server / FakeServer
dotnet run [--file] [ - -urls]
#like所以在我的情况下:
dotnet run --file data.json --urls http://192.168.1.192:57602
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:
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?
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 ask for a firewall exception.
Another solution si to switch to .NET server - another free simple fake server where I can setup local IP as endpoint.
All it needs to:
- install .NET
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
这篇关于json-server无法通过本地IP访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!