-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
37 lines (29 loc) · 1.25 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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const express = require('express');
const { serverConfig } = require('./server/config');
const adminRouter = require('./server/routes/admin');
const parkRouter = require('./server/routes/park');
const tokenRouter = require('./server/routes/token');
const entriesList = require('./server/data/entries');
const app = express();
const router = express.Router();
router.use('/', express.static('app/public'));
router.get('/', function (req, res) {
res.sendFile('app/public/park.html', { root: __dirname });
});
router.get('/health', function (req, res) {
var data = { config: serverConfig, answersSubmitted: entriesList.length };
res.send(data);
});
// Allow cors
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS");
res.setHeader("Access-Control-Expose-Headers", "content-type, authorization, if-none-match");
res.setHeader("Access-Control-Allow-Headers", "content-type, authorization, if-none-match");
next();
});
app.use('/', router);
app.use('/api', adminRouter);
app.use('/api', tokenRouter);
app.use('/api/park', parkRouter);
app.listen(app.listen(serverConfig.port, () => console.log(`App listening on port ${serverConfig.port}!`)));