scalra
Version:
node.js framework to prototype and scale rapidly
37 lines (31 loc) • 1.12 kB
JavaScript
var http = require('http'),
httpProxy = require('http-proxy');
//
// Create your proxy server and set the target in the options.
//
//httpProxy.createProxyServer({target:'http://localhost:9000'}).listen(8000);
//
// 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 = require('http').createServer(function(req, res) {
// You can define here your custom logic to handle the request
// and then proxy the request.
//proxy.web(req, res, { target: 'http://127.0.0.1:9000' });
proxy.web(req, res, { target: 'http://211.78.245.176:37074' });
});
console.log("listening on port 5050")
server.listen(5050);
//
// Create your target server
//
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);