Skip to content

Instantly share code, notes, and snippets.

@svennam92
Last active September 8, 2015 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svennam92/24279eff13a216407cc8 to your computer and use it in GitHub Desktop.
Save svennam92/24279eff13a216407cc8 to your computer and use it in GitHub Desktop.
//var express = require('express');
//var app = express();
//var proxy = require('http-proxy');
//var apiProxy = proxy.createProxyServer({changeOrigin: true});
//
//app.use('/*', function(req, res) {
// var proxiedUrl = req.baseUrl;
// var url = require('url');
// var url_parts = url.parse(req.url, true);
// console.log(url_parts.host);
// if(url_parts.host != null) {
// apiProxy.web(req, res, {
// target: "http://" + url_parts.host + ":80"
// });
// }
//});
//
//app.listen(process.env.PORT || 9000);
var http = require('http');
http.createServer(onRequest).listen(3000);
function onRequest(client_req, client_res) {
console.log('serve: ' + client_req.url);
console.log(client_req.headers.host);
var options = {
hostname: client_req.headers.host,
port: 80,
path: client_req.url,
method: 'GET'
};
var proxy = http.request(options, function (res) {
res.pipe(client_res, {
end: true
});
});
client_req.pipe(proxy, {
end: true
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment