问题
I have an employees
endpoint with some data in my db.json
. I'm using node v6.14.9.
My server.js
looks like this:
// server.js
const jsonServer = require('json-server')
const server = jsonServer.create()
const router = jsonServer.router('db.json')
const middlewares = jsonServer.defaults()
server.use(middlewares)
server.use(jsonServer.rewriter({
'/api/*': '/$1'
}))
server.use(router)
server.listen(3000, () => {
console.log('JSON Server is running')
})
Server starts on port 3000. If I open http://localhost:3000/employees, it works fine. However, opening http://localhost:3000/api/employees throws error 404 not found. Any suggestion what I'm doing wrong?
来源:https://stackoverflow.com/questions/65560532/jsonserver-not-redirecting-using-rewriter