e.g. api 為:"https://gogle.eg.com/comments/get-comments" mock.js 為:
// mockjs 模板
let getComments = mockjs.mock({ code: 200, .... })
let getReplys = mockjs.mock({ code: 200, .... })
// mock.js 產出的 db data:
module.exports = () => {
let data = {
// url 接口: let 變數,
comments: getComments,
replys: getReplys
}
return data
}
routes.json 為:
{
"/comments/get-comments": "/comments/",
"/reply/add-reply": "/reply/"
// "瀏覽器上 localhost:xxxx 後面的 url": db data 的 "/key/"
}
範例
json-server db.json --routes routes.json
routes.json + mock.js
json-server mock.js -w -p 3000 --routes routes.json