【发布时间】:2021-01-03 11:09:12
【问题描述】:
我正在与json-server 合作。我已经用npm install -g json-server 安装了它,并且正在使用
json-server --watch db.json
我在 app 文件夹中添加了db.json 文件,其中包含以下数据
{
"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 不工作。我该如何解决这个问题?
【问题讨论】:
-
json-server启动时是否有任何输出?我看到它列出了资源端点,包括工作正常的http://localhost:3000/product。您发布的 JSON 格式不正确,尾随逗号无效,但我认为这是将其缩减为发布的人工制品(因为如果给定格式不正确的 JSON,则会出现json-server错误)。请给minimal reproducible example。 -
@jonrsharpe - 我已经更新了我的问题。请检查一下。
-
它们是默认值,大概您还看到“糟糕,db.json 似乎不存在”?发布(并阅读!)所有您给出的输出。
-
您是否仔细检查了它正在加载的 db.json 的实际内容?第一次运行它时,如果找不到您要求的文件,它会写出自己的默认值供您编辑。当这种情况发生时,它会告诉你它正在这样做。
-
@jonrsharpe - 现在可以使用了。另一个 db.json 正在不同级别创建。我之前没有注意到这一点。现在可以发布我自己的 json 并获取 url 浏览。