-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
29 lines (25 loc) · 855 Bytes
/
index.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 cors = require('cors');
const path = require('path');
const databasePath = 'data/db.json';
// const databasePath = 'data/db_full.json'; // for bigger dataset (16Mb instead of 4.4Mb)
const distPath = 'dist/population';
const server = jsonServer.create();
const router = jsonServer.router(databasePath);
const middlewares = jsonServer.defaults({
static: path.join(__dirname, distPath)
});
const port = process.env.PORT || 3000;
server.use(cors());
server.use(middlewares);
server.use(router);
server.use((req, res, next) => {
res.header("Cache-Control", "public, max-age=86400000");
next();
});
server.get('/', (req, res) => {
res.sendFile(path.join(`${__dirname}/${distPath}/index.html`));
});
server.listen(port, () => {
console.log(`JSON Server is running on http://localhost:${port}`);
});