Skip to content

Instantly share code, notes, and snippets.

@rtwalz
Created July 23, 2018 17:18
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 rtwalz/c4e44c1d22187cfa0561843f0393122a to your computer and use it in GitHub Desktop.
Save rtwalz/c4e44c1d22187cfa0561843f0393122a to your computer and use it in GitHub Desktop.
Extremely simple reverse proxy in Node.js using Express and Request
var express = require('express');
var app = express();
var request = require('request');
app.get('/', function(request, response) {
response.send("OK")
});
//now you can go to domain.com/(URI ENCODED VERSION OF A URL) to access that page
//example: domain.com/https%3A%2F%2Fgoogle.com to get the Google homepage
app.get('/:d', function(req,res){
res.setHeader('Access-Control-Allow-Origin', '*');
request(decodeURIComponent(req.params.d)).pipe(res);
})
var listener = app.listen(process.env.PORT, function() {
console.log('Your app is listening on port ' + listener.address().port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment