I need to create application which get request for specific port and proxy it to new server on different port
for example the following port 3000 will be proxy to port 9000 and you actually run the application on 9000 ( under the hood) since the user in the client click on 3000
I try something like
var proxy = httpProxy.createProxyServer({});
http.createServer(function (req, res) {
var hostname = req.headers.host.split(":")[0];
var pathname = url.parse(req.url).pathname;
proxy.web(req, res, {
target: 'http://' + hostname + ':' + 9000
});
var proxyServer = http.createServer(function (req, res) {
res.end("Request received on " + 9000);
});
proxyServer.listen(9000);
}).listen(3000, function () {
});
- Is the right way to do it?
- How can I test it? I ask since if I run the node application in port 3000 I cannot put the first URL in the client http://localhost:3000/a/b/c since this port is already taken. Is there a workaround?