UNPKG

1.7 kBJavaScriptView Raw
1var express = require('express')
2var webpack = require('webpack')
3var config = require('./webpack.dev.conf')
4var proxyMiddleware = require('http-proxy-middleware')
5var httpProxy = require('http-proxy')
6
7var app = express()
8var compiler = webpack(config)
9var proxy = httpProxy.createProxyServer({proxyTimeout: 600000})
10
11// Define HTTP proxies to your custom API backend
12// https://github.com/chimurai/http-proxy-middleware
13var proxyTable = {
14 '/rs': {
15 target: 'http://127.0.0.1:8091/ldap'
16 }
17}
18
19var devMiddleware = require('webpack-dev-middleware')(compiler, {
20 publicPath: config.output.publicPath,
21 stats: {
22 colors: true,
23 chunks: false
24 }
25})
26
27var hotMiddleware = require('webpack-hot-middleware')(compiler)
28// force page reload when html-webpack-plugin template changes
29compiler.plugin('compilation', function (compilation) {
30 compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
31 hotMiddleware.publish({ action: 'reload' })
32 cb()
33 })
34})
35
36// proxy api requests
37Object.keys(proxyTable).forEach(function (context) {
38 var options = proxyTable[context]
39 if (typeof options === 'string') {
40 options = { target: options }
41 }
42 app.use(proxyMiddleware(context, options))
43})
44
45// handle fallback for HTML5 history API
46app.use(require('connect-history-api-fallback')())
47
48// serve webpack bundle output
49app.use(devMiddleware)
50
51// enable hot-reload and state-preserving
52// compilation error display
53app.use(hotMiddleware)
54
55// serve pure static assets
56app.use('/static', express.static('./static'))
57
58module.exports = app.listen(8083, function (err) {
59 if (err) {
60 console.log(err)
61 return
62 }
63 console.log('Listening at http://localhost:8083')
64})