Last active
August 3, 2018 08:43
-
-
Save claytonbez/42dce2482885a354a439bd9f819544d8 to your computer and use it in GitHub Desktop.
Express JS proxy script with client example
This file contains hidden or 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
//SERVER SCRIPT | |
var express = require('express'); | |
var app = express(); | |
var request = require('request'); | |
app.get('/:forwardParams',function(req,res){ | |
request.get('http://www.google.com/' + req.params.forwardParams, function (err, response) { | |
if(!err){ | |
res.send(response.body); | |
} | |
else{ | |
res.sendStatus(response.statusCode); | |
} | |
}); | |
}); | |
app.listen(8000); | |
//CLIENT SCRIPT | |
var request = require('request'); | |
request('http://localhost:8000/search?q=express+js', function (err, response) { | |
if(err) console.log(err); | |
console.log(response.body); | |
}); | |
/* So what does this do? Basically you port all requests to google via another http server. Meant to showcase the ease of implementation. | |
A lot can still be done to improve on this script to handle all kinds of forwards. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment