I use this code I want to create proxy that all the application calls to port 3000 will be routed "under the hood" to port 3002
var http = require('http'),
httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer();
http.createServer(function (req, res) {
proxy.web(req, res, {
target: 'http://localhost:3002'
});
}).listen(3000);
// Create target server
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(3002);
Now when I run the application with original port(3000) I see in the browser
request successfully proxied to 3002
When I change the port (in the browser ) to 3002 I still get the same message,why ? is it OK?
What should I put in production inside the second create server ? I mean instead of the
res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); res.end();
Does the
res.end()
should also be there ?
I use the code from https://github.com/nodejitsu/node-http-proxy