我使用json-server,代码如下。
db.json
{
"en-boards": [
{
"id": 0,
"name": "News",
"uri": "/board/en-news"
},
{
"id": 1,
"name": "Politics",
"uri": "/board/en-politics"
}
],
"board-en-news-threads-latest": [
{
"id": 0,
"poster": null,
"zero-post": "This is a thread 0.",
"attachment-path": null,
"post-number": 100,
"utc-timestamp": "2022-01-01T00:00:00"
},
{
"id": 1,
"poster": null,
"zero-post": "This is a thread 1.",
"attachment-path": null,
"post-number": 100,
"utc-timestamp": "2022-01-01T00:00:00"
}
]
}
routes.json
{
"/api/*": "/$1",
"/api/en-boards": "en-boards",
"/api/board/en-news/threads/latest": "board-en-news-threads-latest"
}
我运行json-server --watch db.json --routes routes.json --middlewares middleware.js --port 4000
当我运行curl -i http://localhost:4000/api/en-boards
时,我得到200 OK
,但当我运行curl -i http://localhost:4000/en-news/threads/latest
时,我得到404 Not Found
。wget
和React应用程序的行为方式相同。
环境
- MacOS 13.0操作系统
- 节点. js 18.11.0
- json服务器0.17.0
- curl 度7.84.0
- 工作1.21.3
- React18.2.0
谢谢你的阅读。任何帮助都将不胜感激。
1条答案
按热度按时间6jjcrrmo1#
以前也遇到过类似的情况...
在我的例子中,我需要像基URL(1)和端点路径(2)这样的东西,如下所示-x1c 0d1x
这将满足以下端点的需求
注意:要将 /API/board/en-news/threads/latest 路由到 /board-en-news-threads-latest,需要保持基本URL的顺序(即)
希望这有帮助:)