forked from ssinuco/burger-queen-api-mock
-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathserver.js
More file actions
24 lines (19 loc) · 686 Bytes
/
server.js
File metadata and controls
24 lines (19 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const fs = require('fs');
const path = require('path');
const jsonServer = require('json-server');
const auth = require('json-server-auth');
const middlewares = jsonServer.defaults()
const app = jsonServer.create();
const router = jsonServer.router(path.join(__dirname, 'db.json'));
const port = process.env.PORT || 8080;
const rules = auth.rewriter(JSON.parse(fs.readFileSync(path.join(__dirname, 'routes.json'))));
// /!\ Bind the router db to the app
app.db = router.db
// You must apply the auth middleware before the router
app.use(middlewares);
app.use(rules);
app.use(auth);
app.use(router);
app.listen(port, () => {
console.log(`JSON Server is running in ${port}`);
});