-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (32 loc) · 1.03 KB
/
app.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
38
39
const path = require('path');
const express = require('express');
const morgan = require('morgan');
const app = module.exports = express();
const api = require('./server/api.js');
const logger = require('./server/logger.js');
const Scores = require('./server/scores.js');
const port = process.env.PORT || 7000;
if (process.env.NODE_ENV !== 'test') {
app.use(morgan('short', {
stream: { write: message => logger.info(message) }
}));
}
app.use(express.static(path.join(__dirname, 'client/build')));
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept');
next();
});
app.use('/scores', api);
app.set('Scores', new Scores());
// Serve babel compiled build of triton
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '/client/build/index.html'));
});
if (process.env.NODE_ENV !== 'test') {
app.listen(port, () => {
logger.info(`Now listening on ${port}`);
});
}
module.exports = { App: app };