我正在使用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/