Created
May 27, 2018 15:27
-
-
Save Dviejopomata/852105ade677596e8838638bd90677e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'), | |
httpProxy = require('http-proxy'); | |
var url = require('url') ; | |
// | |
// Create a proxy server with custom application logic | |
// | |
var proxy = httpProxy.createProxyServer({}); | |
// | |
// Create your custom server and just call `proxy.web()` to proxy | |
// a web request to the target passed in the options | |
// also you can use `proxy.ws()` to proxy a websockets request | |
// | |
var server = http.createServer(function(req, res) { | |
var q = url.parse(req.url,true).query; | |
console.log(q.dst) | |
const dst = { | |
pru_app_tenant1:"http://127.0.0.1:5061", | |
pru_app_tenant2:"http://127.0.0.1:5062", | |
pru_app_tenant3:"http://127.0.0.1:5063", | |
pru_app_tenant4:"http://127.0.0.1:5064" | |
} | |
proxy.web(req, res, { target: dst[q.dst] }); | |
}); | |
console.log("listening on port 5050") | |
server.listen(5050); | |
var server2 = http.createServer(function(req, res) { | |
var q = url.parse(req.url,true).query; | |
q.server = "5064" | |
res.write(JSON.stringify(q) ); | |
res.end(); | |
}).listen(5064); | |
var server2 = http.createServer(function(req, res) { | |
var q = url.parse(req.url,true).query; | |
q.server = "5061" | |
res.write(JSON.stringify(q) ); | |
res.end(); | |
}).listen(5061); | |
var server2 = http.createServer(function(req, res) { | |
var q = url.parse(req.url,true).query; | |
q.server = "5062" | |
res.write(JSON.stringify(q) ); | |
res.end(); | |
}).listen(5062); | |
var server2 = http.createServer(function(req, res) { | |
var q = url.parse(req.url,true).query; | |
q.server = "5063" | |
res.write(JSON.stringify(q) ); | |
res.end(); | |
}).listen(5063); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment