Skip to content

Instantly share code, notes, and snippets.

@chevcast
Last active August 29, 2015 14:05
Show Gist options
  • Save chevcast/2969118335b2f969e74a to your computer and use it in GitHub Desktop.
Save chevcast/2969118335b2f969e74a to your computer and use it in GitHub Desktop.
router.get('/google', function (req, res) {
var url = 'http://www.google.com';
request(url, function (err, response, body) {
res.send(body.replace(/(action|src|href)="((?!http)[^"]*)"/gi, function (match, g1, g2) {
return g1 + '="' + url + g2 + '"';
}));
});
});
@chevcast
Copy link
Author

I faked the user-agent header as well and now the sites think my server-side requests come from Chrome.

router.get('*', function (req, res) {
  var url = req.param('site');
  request({
    url: url,
    headers: {
      'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36'
    }
  }, function (err, response, body) {
    res.send(body.replace(/(action|src|href)="((?!http)[^"]*)"/gi, function (match, g1, g2) {
      return g1 + '="' + url + g2 + '"';
    }));
  });
});

Now you can pass any website as a query parameter.
(e.g. http://localhost:3000?site=http://twitter.com)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment