-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.dev.js
49 lines (37 loc) · 1.42 KB
/
server.dev.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
import express from 'express'
import path from 'path'
import webpack from 'webpack'
import webpackDevMiddleware from 'webpack-dev-middleware'
import webpackHotMiddleware from 'webpack-hot-middleware'
import config from './webpack.config.dev'
var app = express()
var compiler = webpack(config)
var devMiddleware = webpackDevMiddleware(compiler, {
// hot: true,
publicPath: config.output.publicPath,
stats: { chunks: false, colors: true }
})
app.use(devMiddleware)
app.use(webpackHotMiddleware(compiler))
app.get('/authentication', function (req, res) {
res.send('Authenticated')
})
//because html5 history is hard
app.use((req, res, next) => {
var paths = req.url.split('/')
var file = paths[paths.length - 1]
if (['bundle.js', 'index.html'].indexOf(file) !== -1) {
res.end(devMiddleware.fileSystem.readFileSync(path.join(config.output.path, file)))
} else if (file.indexOf('.') === -1) {
res.end(devMiddleware.fileSystem.readFileSync(path.join(config.output.path, 'index.html')))
} else {
next()
}
})
var port = process.env.PORT
app.listen(port, () => {
console.log('===================================================================================')
console.log(`Prism Application Server Online. Port: ${port}. Environment: ${process.env.NODE_ENV}`)
console.log('===================================================================================')
console.log('webpack building...')
})