无法从另一台设备连接到 json-server

Can't connect to json-server from another device

我从 https://github.com/typicode/json-server 安装了 json-server 并且工作正常,我可以执行 GET、POST 等,但仅限于本地。当我尝试从外部连接时,它不起作用。

我尝试关闭防火墙、更改端口和不同的启动设置(即 json-server --host 192.168.0.21 db.json),但没有任何帮助。这是我的数据库。


[
  {
    "id": 2,
    "login": "admin3",
    "haslo": "haslo3"
  },
  {
    "id": 3,
    "login": "admin2",
    "haslo": "haslo2"
  },
  {
    "login": "admin1",
    "haslo": "haslo1",
    "id": 7
  }
]

我希望能够从全世界连接到我的服务器,但只有本地地址有效(即 http://192.168.0.21:3000/user or http://localhost:3000/user)。我的方法有什么问题?

确保您正在启动绑定到适配器的服务器(例如 --host 0.0.0.0)。

然后你需要在你的路由器上设置端口转发。

https://deaddesk.top/exposing-local-server-to-the-public-internet/