Skip to content

Commit

Permalink
Merge pull request #284 from weaveworks/fix-js-landing
Browse files Browse the repository at this point in the history
Fix JS on production page
  • Loading branch information
davkal committed Jan 13, 2016
2 parents 7411493 + 7dc64a2 commit 3a6d117
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
7 changes: 4 additions & 3 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"history": "1.13.1",
"material-ui": "0.13.3",
"page": "1.6.4",
"react": "0.14.3",
"react": "0.14.6",
"react-cookie-banner": "davkal/react-cookie-banner#dc5f4c1bf43c0dc65ed6fd909991871b2a1dce31",
"react-dom": "0.14.3",
"react-dom": "0.14.6",
"react-motion": "0.3.1",
"react-router": "1.0.0",
"react-tap-event-plugin": "0.2.1"
Expand All @@ -58,8 +58,9 @@
"body-parser": "1.13.3",
"express": "4.13.3",
"coveralls": "2.11.3",
"proxy-middleware": "0.15.0",
"http-proxy": "^1.12.0",
"react-hot-loader": "1.2.8",
"socks-proxy-agent": "^2.0.0",
"webpack-dev-server": "~1.10.1"
},
"jest": {
Expand Down
22 changes: 19 additions & 3 deletions client/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var express = require('express');
var bodyParser = require('body-parser');
var proxy = require('proxy-middleware');
var httpProxy = require('http-proxy');
var url = require('url');
var SocksProxyAgent = require('socks-proxy-agent');

var app = express();
if (process.env.USE_MOCK_BACKEND) {
Expand Down Expand Up @@ -40,7 +41,20 @@ app.get('/app.js', function(req, res) {

// Proxy to backend

app.use('/api', proxy(url.parse('http://localhost:4047/api')));
var proxyOpts = {
target: 'http://localhost:4047',
ws: true
};
if (process.env.USE_SOCKS_PROXY) {
proxyOpts.agent = new SocksProxyAgent({host: 'localhost', port: 8000, protocol: 'socks5:'});
}
var proxy = httpProxy.createProxy(proxyOpts);

proxy.on('error', function(err) {
console.error('Proxy error', err);
});

app.all('/api*', proxy.web.bind(proxy));

// Mock backend

Expand Down Expand Up @@ -96,7 +110,7 @@ if (process.env.USE_MOCK_BACKEND) {
mailSent: !!req.body.email,
email: req.body.email
});
});
});

app.get('/login', function(req, res) {
res.redirect('org/foo');
Expand Down Expand Up @@ -154,3 +168,5 @@ var server = app.listen(port, function () {

console.log('Scope Account Service UI listening at http://%s:%s', host, port);
});

server.on('upgrade', proxy.ws.bind(proxy));

0 comments on commit 3a6d117

Please sign in to comment.