javascript - json-server 不显示 JSON 数据的 URL

标签 javascript json-server

我正在使用json-server。我已经使用 npm install -g json-server 安装了它,并且正在使用

观看
json-server --watch db.json

我已在应用程序文件夹中添加了 db.json 文件,其中包含以下数据

{
    "product": [
      {
        "userId": 1,
        "firstName": "Krish",
        "lastName": "Lee",
        "phoneNumber": "123456",
        "emailAddress": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="28435a415b4006444d4d68444d495a4641464f4b47465c4941464d5a064b4745" rel="noreferrer noopener nofollow">[email protected]</a>"
      },
      {
        "userId": 5,
        "firstName": "jone",
        "lastName": "mac",
        "phoneNumber": "111111111",
        "emailAddress": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="066c696863286b6765466a636774686f686165696872676f6863742865696b" rel="noreferrer noopener nofollow">[email protected]</a>"
      }
    ]
  }

但只有 http://localhost:3000/ 正在工作。它显示

Congrats!
You're successfully running JSON Server
✧*。٩(ˊᗜˋ*)و✧*。

Resources
/posts 1x
/comments 1x
/profile object
To access and modify resources, you can use any HTTP method:

GET POST PUT PATCH DELETE OPTIONS

undefined
Documentation
README

To replace this page, create a ./public/index.html file.

http://localhost:3000/product 不起作用。我该如何解决这个问题?

最佳答案

第一次尝试运行 json-server 时,如果找不到提供的源,load.js为您写出默认示例:


> json-server --watch db.json


  \{^_^}/ hi!

  Loading db.json
  <b>Oops, db.json doesn't seem to exist
  Creating db.json with some default data</b>

  Done

  Resources
  http://localhost:3000/posts
  http://localhost:3000/comments
  http://localhost:3000/profile

  Home
  http://localhost:3000

在后续运行中,由于该文件现在存在,服务器似乎启动得很好,但没有使用您认为的 db.json 文件。出于这个原因,这似乎有点错误,我opened a PR要求明确请求此行为。

关于javascript - json-server 不显示 JSON 数据的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63923087/

相关文章:

npm - 无法安装 json 服务器

javascript - 飞溅 API/lua 错误 : attempt to index local element (a nil value)

javascript - 使用 AJAX 的 POST 文件数据附加未知的 jquery 回调字符串

javascript - 无法在 JSON-SERVER 中获取对象关键数据

node.js - 在 Heroku 上部署 React 应用和 API 的最佳实践

javascript - 是否可以在 json 中进行表达式/计算?

javascript - Angular 2 ChangeDetectionStrategy.OnPush 在输入不改变时触发 ngAfterViewChecked

javascript - 如何从输入文件设置背景图像?

javascript - this.moveImage 不是一个函数

server - json-server 无法通过本地 IP 访问