-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevServer.js
More file actions
54 lines (44 loc) · 1.37 KB
/
Copy pathdevServer.js
File metadata and controls
54 lines (44 loc) · 1.37 KB
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
const express = require('express')
const path = require('path')
const webpack = require('webpack')
const webpackDevMiddleware = require('webpack-dev-middleware')
const webpackHotMiddleware = require('webpack-hot-middleware')
const httpProxy = require('http-proxy')
const webpackConfig = require('./webpack.config')
const app = express()
const apiProxy = httpProxy.createProxyServer()
const compiler = webpack(webpackConfig)
const port = process.env.PORT || 5000
app.use(express.static(path.join(process.cwd(), 'assets')))
app.use(webpackDevMiddleware(compiler, {
noInfo: true,
publicPath: webpackConfig.output.publicPath
}))
app.use(webpackHotMiddleware(compiler))
app.set('view engine', 'ejs')
app.set('views', path.join(process.cwd(), 'example'))
function renderIndex (req, res) {
res.render('index')
}
app.get('/contexts/:context/scenarios/:scenario/view', renderIndex)
app.get('/contexts/:context/scenarios/:scenario', renderIndex)
app.get('/contexts/:context', renderIndex)
app.get('/fetch-css', renderIndex)
app.get('/demo', renderIndex)
app.get('/', renderIndex)
app.use("/api/*", function (req, res) {
req.url = req.baseUrl
apiProxy.web(req, res, {
target: {
port: 5001,
host: "localhost"
}
})
})
app.listen(port, '0.0.0.0', err => {
if (err) {
console.error(err)
process.exit(1)
}
console.log(`Listening at http://localhost:${port}`)
})