This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Node Proxy Method Passthrough

By: a guest on Sep 23rd, 2011  |  syntax: None  |  size: 0.75 KB  |  views: 89  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. var express = require('express')
  2. var app = express.createServer(express.bodyParser());
  3. var request = require('request'),
  4. sys = require('sys'),
  5. fs=require('fs');
  6.  
  7. app.all('/url', function(req, res){
  8.   console.log(req.query.link);
  9.   var options = {
  10.             uri: req.query.link,
  11.             method: req.method,
  12.             headers: {"User-Agent": "Mozilla/5.0 (Windows  NT 6.1; rv:6.0) Gecko/20110814 Firefox/6.0"}
  13.            }
  14.   if(req.body)
  15.     options.body = req.body
  16.  
  17.   request( options, function (error, response, body) {
  18.  
  19.              if (error && response.statusCode !== 200) {    
  20.                console.log('Error when contacting google.com')
  21.              }
  22.  
  23.   res.send(body, {"Content-type": "text/html"});
  24.   res.end();
  25.  
  26.   });
  27. });
clone this paste RAW Paste Data