forked from LetsGetChecked/developer-challenge-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
29 lines (24 loc) · 828 Bytes
/
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
24
25
26
27
28
29
const jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('./api/db.json');
const port = process.env.PORT || 8080;
const middlewares = jsonServer.defaults({ static: './dist/lgc-frontend-challenge' });
server.db = router.db;
server.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Methods', 'GET, POST, DELETE, PATCH, PUT')
res.header('Access-Control-Allow-Headers', '*')
next()
})
server.use('/api', router);
server.use(middlewares);
server.all('*', (req, res) => {
res.status(200).sendFile(__dirname + '/dist/lgc-frontend-challenge/index.html');
});
server.listen(port), {
cors: {
origin: "*",
methods: ["PUT", "GET", "POST", "DELETE"],
credentials: false
}
}