mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
Use existing ember proxy config within our custom proxy
This commit is contained in:
@@ -5,5 +5,6 @@
|
|||||||
|
|
||||||
Setting `disableAnalytics` to true will prevent any data from being sent.
|
Setting `disableAnalytics` to true will prevent any data from being sent.
|
||||||
*/
|
*/
|
||||||
"disableAnalytics": false
|
"disableAnalytics": false,
|
||||||
|
"proxy": "http://127.0.0.1:4646"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ module.exports = function(app, options) {
|
|||||||
// For options, see:
|
// For options, see:
|
||||||
// https://github.com/nodejitsu/node-http-proxy
|
// https://github.com/nodejitsu/node-http-proxy
|
||||||
|
|
||||||
|
let proxyAddress = options.proxy;
|
||||||
|
|
||||||
let server = options.httpServer;
|
let server = options.httpServer;
|
||||||
let proxy = require('http-proxy').createProxyServer({
|
let proxy = require('http-proxy').createProxyServer({
|
||||||
target: 'http://localhost:4646',
|
target: proxyAddress,
|
||||||
ws: true,
|
ws: true,
|
||||||
changeOrigin: true
|
changeOrigin: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
proxy.on('error', function(err, req) {
|
proxy.on('error', function(err, req) {
|
||||||
@@ -19,16 +21,16 @@ module.exports = function(app, options) {
|
|||||||
console.error(err, req.url);
|
console.error(err, req.url);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use(proxyPath, function(req, res){
|
app.use(proxyPath, function(req, res) {
|
||||||
// include root path in proxied request
|
// include root path in proxied request
|
||||||
req.url = proxyPath + req.url;
|
req.url = proxyPath + req.url;
|
||||||
proxy.web(req, res, { target: 'http://localhost:4646'});
|
proxy.web(req, res, { target: proxyAddress });
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on('upgrade', function (req, socket, head) {
|
server.on('upgrade', function(req, socket, head) {
|
||||||
if (req.url.startsWith('/v1/client/allocation') && req.url.includes('exec?')) {
|
if (req.url.startsWith('/v1/client/allocation') && req.url.includes('exec?')) {
|
||||||
req.headers.origin = 'http://localhost:4646';
|
req.headers.origin = proxyAddress;
|
||||||
proxy.ws(req, socket, head, { target: 'http://localhost:4646'});
|
proxy.ws(req, socket, head, { target: proxyAddress });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user