-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
50 lines (39 loc) · 1.28 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
49
50
var http = require('http');
var httpProxy = require('http-proxy');
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');
var express = require('express');
var app = express();
var proxy = httpProxy.createProxyServer();
var compiler = webpack(config);
// var proxyTo = 'PROXY_URL';
// app.all('/api/*', function(req, res) {
// delete req.headers.host;
// req.url = req.url.replace('/api', '/');
// proxy.web(req, res, {target: proxyTo});
// });
app.get('/js/*', function(req, res) {
proxy.web(req, res, {target: 'http://localhost:3001'});
});
app.get('/socket*', function(req, res) {
proxy.web(req, res, {target: 'http://localhost:3001'});
});
app.use(express.static(__dirname));
app.all('/*', function(req, res) {
res.sendFile(__dirname + '/index.html');
});
server = http.createServer(app);
server.on('upgrade', function(req, socket, head) {
proxy.ws(req, socket, head, {target: 'http://localhost:3001'});
});
server.listen(3000);
new WebpackDevServer(compiler, {
publicPath: config.output.publicPath,
hot: true
}).listen(3001, 'localhost', function (err, result) {
if (err) {
console.log(err);
}
console.log('Listening at localhost:3001');
});