Skip to content

Instantly share code, notes, and snippets.

@spiermar
Created October 2, 2015 23:57
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 spiermar/69db9cc3762c850e0fb4 to your computer and use it in GitHub Desktop.
Save spiermar/69db9cc3762c850e0fb4 to your computer and use it in GitHub Desktop.
Node.JS Express Proxy
var http = require('http');
var app = require('express')();
app.use('/proxy*', function(req, res, next) {
var options = {
host: "spiermar.github.io",
path: "/contact" + req.params[0]
};
var callback = function(response) {
if (response.statusCode === 200) {
res.writeHead(200, {
'Content-Type': response.headers['content-type']
});
response.pipe(res);
} else {
res.writeHead(response.statusCode);
res.end();
}
};
http.request(options, callback).end();
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment