mirror of
https://github.com/Nezumi-2711/json-server-vercel.git
synced 2026-09-22 13:38:40 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// See https://github.com/typicode/json-server#module
|
||||
const jsonServer = require('json-server')
|
||||
|
||||
const server = jsonServer.create()
|
||||
|
||||
// Uncomment to allow write operations
|
||||
// const fs = require('fs')
|
||||
// const path = require('path')
|
||||
// const filePath = path.join('db.json')
|
||||
// const data = fs.readFileSync(filePath, "utf-8");
|
||||
// const db = JSON.parse(data);
|
||||
// const router = jsonServer.router(db)
|
||||
|
||||
// Comment out to allow write operations
|
||||
const router = jsonServer.router('db.json')
|
||||
|
||||
const middlewares = jsonServer.defaults()
|
||||
|
||||
server.use(middlewares)
|
||||
// Add this before server.use(router)
|
||||
server.use(jsonServer.rewriter({
|
||||
'/api/*': '/$1',
|
||||
'/blog/:resource/:id/show': '/:resource/:id'
|
||||
}))
|
||||
server.use(router)
|
||||
server.listen(3000, () => {
|
||||
console.log('JSON Server is running')
|
||||
})
|
||||
|
||||
// Export the Server API
|
||||
module.exports = server
|
||||
Reference in New Issue
Block a user