不使用id

时间:2018-11-14 09:49:57

标签: javascript json angular json-server

我想在内存中使用模拟休息电话进行角度应用。大多数数据将没有ID作为对象的标识符。所以尝试在json服务器中的自定义路由,但出现错误。我正在将json-server与以下数据 db.json

{
  "author": [
    {
      "age": 22,
      "name": "Lisa"
    },
    {
      "age": 50,
      "name": "ManishRane"
    }
  ]
}

尝试为上述数据编写自定义路由,以执行其余操作,如GET,POST,PUT,DELETE。我尝试了以下路线:

{   
    "/author/:name": {
      "GET": "/author?name=:name",
      "POST": "/author/:name",
      "PUT": "/author/:name",
      "PATCH": "/author/:name",
      "DELETE": "/author/:name"
    }
}

上述路线的

参考是:https://github.com/typicode/json-server/issues/802

错误:

TypeError: (dst || src).replace is not a function
    at C:\Users\manirane\AppData\Roaming\npm\node_modules\json-server\node_modules\express-urlrewrite\index.js:45:28
    at Layer.handle [as handle_request] (C:\Users\manirane\AppData\Roaming\npm\node_modules\json-server\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\Users\manirane\AppData\Roaming\npm\node_modules\json-server\node_modules\express\lib\router\index.js:317:13)
    at C:\Users\manirane\AppData\Roaming\npm\node_modules\json-server\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\Users\manirane\AppData\Roaming\npm\node_modules\json-server\node_modules\express\lib\router\index.js:335:12)
    at next (C:\Users\manirane\AppData\Roaming\npm\node_modules\json-server\node_modules\express\lib\router\index.js:275:10)
    at Function.handle (C:\Users\manirane\AppData\Roaming\npm\node_modules\json-server\node_modules\express\lib\router\index.js:174:3)
    at router (C:\Users\manirane\AppData\Roaming\npm\node_modules\json-server\node_modules\express\lib\router\index.js:47:12)
    at Layer.handle [as handle_request] (C:\Users\manirane\AppData\Roaming\npm\node_modules\json-server\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\Users\manirane\AppData\Roaming\npm\node_modules\json-server\node_modules\express\lib\router\index.js:317:13)

0 个答案:

没有答案