我正在使用json-server来模拟rest API。
我计划为每个API提供模拟逻辑,但是下面的代码段不允许获取db.json文件中指定的路由(即使/ login route按预期工作)
// Add custom routes before JSON Server router
server.get('/login', (req, res) => {
res.json({
token: '777777'
})
})
// continue doing json-server magic
server.use(router);
db.json条目是:
{
"posts": [
{
"id": 1,
"title": "json-server",
"author": "typicode"
},
{
"id": 11,
"title": "json-server",
"author": "typicode"
}],
"comments": [
{
"id": 1,
"body": "some comment",
"postId": 1
}],
"profile": {
"name": "typicode"
}
}