-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
36 lines (30 loc) · 993 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
30
31
32
33
34
35
36
const express = require('express');
const app = express();
const Promise = require('bluebird');
const bodyParser = require('body-parser');
const checkpoint = require('./routes/checkPoints');
const path = require('path');
const isDeveloping = process.env.NODE_ENV !== 'production';
const port = isDeveloping ? 3000 : process.env.PORT;
const host = isDeveloping ? 'localhost' : '0.0.0.0';
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
const PUBLIC_PATH = path.resolve('./public');
app.use(express.static(PUBLIC_PATH));
Promise.onPossiblyUnhandledRejection((err) => {
throw new Error(err);
});
app.get('/play', (req, res) => {
res.sendFile(path.resolve(PUBLIC_PATH, 'play.html'));
})
app.use('/api/checkpoint', checkpoint);
const onStart = (err) => {
if (err) {
throw new Error(err);
}
console.info(
`==> 🌎 Listening on port ${port}. ` +
`Open up http://${host}:${port}/ in your browser.`
);
};
app.listen(port, host, onStart);