Last active
September 8, 2015 21:43
-
-
Save svennam92/24279eff13a216407cc8 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 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