【问题标题】:Can't connect to json-server from another device无法从其他设备连接到 json-server
【发布时间】:2019-12-21 08:43:04
【问题描述】:

我从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/userhttp://localhost:3000/user)。我的方法有什么问题?

【问题讨论】:

    标签: node.js json-server


    【解决方案1】:

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

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

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

    【讨论】:

    • 我知道这是一个旧答案,但我遇到了同样的问题并且有一个问题。如何找到绑定到我的适配器的服务器?
    猜你喜欢
    • 2021-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-18
    • 2020-10-23
    • 1970-01-01
    • 2022-11-06
    • 2014-04-13
    相关资源
    最近更新 更多