-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
48 lines (39 loc) · 1.12 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
'use strict'
const webpack = require('webpack')
const webpackDevMiddleware = require('webpack-dev-middleware')
const webpackHotMiddleware = require('webpack-hot-middleware')
const express = require('express')
const config = require('./webpack.config')
const compiler = webpack(config)
const app = express()
const port = 8000
app.use(webpackDevMiddleware(compiler, {
noInfo: true,
publicPath: config.output.publicPath,
stats: {
colors: true,
},
}))
app.use(webpackHotMiddleware(compiler))
app.get('/', (req, res) => {
res.sendFile(`${__dirname}/src/index.html`)
})
app.get('/*', (req, res) => {
res.sendFile(`${__dirname}/src/${req.path}`)
})
app.get('/api/*', (req, res) => {
// Simulate RESTful API request for development
let path = req.path
path = /\/comics\/[\d]+(\/episodes)?/.test(path) ? `${path}/data` : path
res.sendFile(`${__dirname}/src/${path}`)
})
app.get('/assets/*', (req, res) => {
res.sendFile(`${__dirname}/src/${req.path}`)
})
app.listen(port, (error) => {
if (error) {
console.error(error)
} else {
console.info('==> Open up http://localhost:%s/ in your browser.', port)
}
})