-
-
Save sh1mmer/562642 to your computer and use it in GitHub Desktop.
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
var sys = require("sys"), | |
http = require("http"), | |
url = require("url"), | |
path = require("path"), | |
fs = require("fs"); | |
function getHostname(str) { | |
var re = new RegExp('^(?:f|ht)tp(?:s)?\://([^/]+)', 'im'); | |
return str.match(re)[1].toString(); | |
} | |
var urlUnwrapper = function() { | |
this.server = http.createServer(function(req, res) { | |
var uri = url.parse(request.url); | |
var host = getHostname(uri.query); | |
var visitURL = url.parse(uri.query); | |
var client = http.createClient(80, host); | |
var request = client.request('GET', visitURL.pathname, | |
{'host': host}); | |
request.end(); | |
request.on('response', function (response) { | |
console.log(response.headers.location); | |
// I want to print this location to the browser! | |
var body = response.headers.location; | |
res.writeHead(200, { 'Content-Length': body.length, 'Content-Type': 'text/plain' }; | |
res.end(body); | |
}); | |
response.sendHeader(200); | |
response.write('well fuck'); | |
response.close(); | |
}).listen(8080); | |
}(); | |
sys.puts("Server running at http://localhost:8080/"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment