-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
60 lines (44 loc) · 1.71 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const express = require('express')
const path = require('path')
const cookieParser = require('cookie-parser')
const bodyParser = require('body-parser')
const cors = require('cors')
const projectVersion = require('project-version')
const { correlationMiddleware } = require('@first-lego-league/ms-correlation')
const { authenticationMiddleware, authenticationDevMiddleware } = require('@first-lego-league/ms-auth')
const { Logger, loggerMiddleware } = require('@first-lego-league/ms-logger')
const DEFAULTS = require('./server/defaults')
const port = process.env.PORT || DEFAULTS.PORT
const app = express()
const logger = new Logger()
logger.info(`-------------------- scoring version ${projectVersion} startup --------------------`)
app.use(cookieParser())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(correlationMiddleware)
app.use(loggerMiddleware)
app.use(cors())
const authMiddleware = process.env.NODE_ENV === 'development' ? authenticationDevMiddleware() : authenticationMiddleware
app.use('/scores', require('./server/scores')(authMiddleware))
app.use('/challenge', require('./server/challenge'))
app.use('/config', require('./server/config'))
if (process.env.NODE_ENV === 'development') {
app.use(require('./server/dev_router'))
}
app.use(authMiddleware)
app.use(express.static(path.resolve(__dirname, 'dist')))
app.listen(port, () => {
logger.info(`Scoring service listening on port ${port}`)
})
process.on('SIGINT', () => {
logger.info('Process received SIGINT: shutting down')
process.exit(130)
})
process.on('uncaughtException', err => {
logger.fatal(err.message)
process.exit(1)
})
process.on('unhandledRejection', err => {
logger.fatal(err.message)
process.exit(1)
})