首页 > 解决方案 > json-server 未显示 JSON 数据的 URL

问题描述

我正在与json-server. 我已经安装它npm install -g json-server并正在观看使用

json-server --watch db.json

db.json在 app 文件夹中添加了包含以下数据的文件

{
    "product": [
      {
        "userId": 1,
        "firstName": "Krish",
        "lastName": "Lee",
        "phoneNumber": "123456",
        "emailAddress": "krish.lee@learningcontainer.com"
      },
      {
        "userId": 5,
        "firstName": "jone",
        "lastName": "mac",
        "phoneNumber": "111111111",
        "emailAddress": "jone.mac@learningcontainer.com"
      }
    ]
  }

但只有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不管用。我该如何解决这个问题?

标签: javascriptjson-server

解决方案


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


> json-server --watch db.json


  \{^_^}/ hi!

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

  Done

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

  Home
  http://localhost:3000

在随后的运行中,由于文件现在存在,服务器似乎启动得很好,但没有使用db.json您认为的文件。出于这个原因,这似乎有点错误,我已经打开了一个 PR要求明确要求这种行为。


推荐阅读