我刚开始使用json-server,并为一件事而苦苦挣扎。我想有网址是嵌套的,例如,为了获得用户组织,请求将如下所示:/rest/user/orgs,并将返回用户组织数组
{
"rest": {
"user": {
"select": {
"org": []
},
"orgs": [{
"id": "5601e1c0-317c-4af8-9731-a1863f677e85",
"name": "DummyOrg"
}],
"logout": {}
}
}
}你知道我做错了什么吗?
发布于 2021-03-08 21:34:34
库不支持这一点。实现这一点的方法是向de服务器添加一个自定义路由文件,您将在其中将对/rest/user/的请求映射(或重定向)到/。
db.json
{
"select": {
"org": []
},
"orgs": [{
"id": "5601e1c0-317c-4af8-9731-a1863f677e85",
"name": "DummyOrg"
}],
"logout": {}
}routes.json
{
"/rest/user/*": "/$1"
}然后使用json-server db.json --routes routes.json运行它
https://stackoverflow.com/questions/43349952
复制相似问题