1 | var express = require('express')
|
2 | var webpack = require('webpack')
|
3 | var config = require('./webpack.example.conf')
|
4 | var proxyMiddleware = require('http-proxy-middleware')
|
5 | var httpProxy = require('http-proxy')
|
6 |
|
7 | var app = express()
|
8 | var compiler = webpack(config)
|
9 | var proxy = httpProxy.createProxyServer()
|
10 |
|
11 |
|
12 |
|
13 | var proxyTable = {
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | }
|
22 |
|
23 | var devMiddleware = require('webpack-dev-middleware')(compiler, {
|
24 | publicPath: config.output.publicPath,
|
25 | stats: {
|
26 | colors: true,
|
27 | chunks: false
|
28 | }
|
29 | })
|
30 |
|
31 | var hotMiddleware = require('webpack-hot-middleware')(compiler)
|
32 |
|
33 | compiler.plugin('compilation', function (compilation) {
|
34 | compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
|
35 | hotMiddleware.publish({ action: 'reload' })
|
36 | cb()
|
37 | })
|
38 | })
|
39 |
|
40 |
|
41 | Object.keys(proxyTable).forEach(function (context) {
|
42 | var options = proxyTable[context]
|
43 | if (typeof options === 'string') {
|
44 | options = { target: options }
|
45 | }
|
46 | app.use(proxyMiddleware(context, options))
|
47 | })
|
48 |
|
49 |
|
50 | app.use(require('connect-history-api-fallback')())
|
51 |
|
52 |
|
53 | app.use(devMiddleware)
|
54 |
|
55 |
|
56 |
|
57 | app.use(hotMiddleware)
|
58 |
|
59 |
|
60 | app.use('/static', express.static('./static'))
|
61 |
|
62 | app.all('/rs/*', function (req, res) {
|
63 | proxy.web(req, res, {
|
64 | target: 'http://127.0.0.1:8081/ldap'
|
65 | })
|
66 | })
|
67 |
|
68 | module.exports = app.listen(8080, function (err) {
|
69 | if (err) {
|
70 | console.log(err)
|
71 | return
|
72 | }
|
73 | console.log('Listening at http://localhost:8080')
|
74 | })
|