This repository has been archived by the owner on Nov 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
60 lines (50 loc) · 1.74 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require('dotenv').config()
const server = require('kth-node-server')
const express = require('express')
const path = require('path')
const apiRouter = require('./server/api')
const prefix = process.env.PROXY_BASE || ''
const PORT = process.env.SERVER_PORT || process.env.PORT || 3000
const bunyan = require('bunyan')
const log = bunyan.createLogger({
name: 'build-monitor',
level: process.env.BUNYAN_LOG_LEVEL || 'info'
})
/* Hot code reloading */
// Important: this should be BEFORE other express.static() calls
if (process.env.NODE_ENV === 'development') {
const webpack = require('webpack')
const config = require('./webpack.dev.js')
const compiler = webpack(config)
log.warn('************ The app is going to start in DEVELOPMENT mode ******')
server.use(require('webpack-dev-middleware')(compiler, {
publicPath: config.output.publicPath,
logger: log
}))
server.use(require('webpack-hot-middleware')(compiler, {
quiet: true
}))
}
/* Middlewares */
server.use((req, res, next) => {
req.log = log.child({
request_path: req.path
})
next()
})
/* Endpoints */
server.use(prefix + '/bootstrap', express.static(path.join(__dirname, '/node_modules/bootstrap/dist')))
server.use(prefix + '/kth-style', express.static(path.join(__dirname, '/node_modules/kth-style/dist')))
server.use(prefix + '/kth-style2', express.static(path.join(__dirname, '/node_modules/kth-style/build')))
server.use(prefix, express.static('public'))
server.use(prefix + '/api', apiRouter)
server.get(prefix + '/_monitor', (req, res) => res.type('text').status(200).send('APPLICATION_STATUS OK'))
/* ****************************
* ******* SERVER START *******
* ****************************
*/
server.start({
useSsl: false,
port: PORT,
logger: log
})