-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
24 lines (20 loc) · 1.03 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//This server is meant to replace the `yarn api`("json-server --watch db.json --port 8080 --id serial_number") since running it this way let us do more customizations so the React Dev keeps up with the sinatra environment i.e.: This change was made so that we could envelope the responses inside the 'data' key
//TODO: maybe we could add code from the json-server repo so that it accepts parameterized options?
//TODO: add code to allow command-line arguments as in json-server executable, so that the options are not hardcoded here e.x.: node server.js --port 6060
const jsonServer = require('json-server')
const server = jsonServer.create()
const router = jsonServer.router('db.json')
const middlewares = jsonServer.defaults()
router.db._.id = "serial_number"
router.render = (req,res) => {
//TODO: add way to override the 'metadata' with query params('?success=false')
res.jsonp({
data: res.locals.data,
success: true
})
}
server.use(middlewares)
server.use(router)
server.listen(8080, () => {
console.log('JSON Server is running')
})