#!/usr/bin/env node
var http = require('http');
var url = require('url');
var request = require('request');
var domain = require('domain');
var port = process.env.PORT || 8080;

var server = http.createServer(function (req, res) {
	var d = domain.create();
	d.on('error', function (e){
		console.log('ERROR', e.stack);

		res.statusCode = 500;
		res.end('Error: ' + ((e instanceof TypeError) ? "make sure your URL is correct" : String(e)));
	});

	d.add(req);
	d.add(res);

	d.run(function() {
		handler(req, res);
	});

}).listen(port);

function handler(req, res) {
	var url_parts = url.parse(req.url, true);
	var auth = url_parts.query.auth;
	var uuu = url_parts.query.url;
	try {
		res.setTimeout(25000);
		res.setHeader('Access-Control-Allow-Origin', '*');
		res.setHeader('Access-Control-Allow-Credentials', false);
		res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
		res.setHeader('Expires', new Date(Date.now() + 86400000).toUTCString()); // one day in the future
		var r = request(uuu, {encoding: null, rejectUnauthorized: false, headers: {
'Authorization': 'bearer ' + auth 
}});
		r.pipe(res);
	} catch (e) {
		res.end('Error: ' +  ((e instanceof TypeError) ? "make sure your URL is correct" : String(e)));
	}
}

@@ -1004,16 +1004,39 @@
 t(uuu, %7B
+followRedirect: false, 
 encoding
@@ -1122,23 +1122,112 @@
  %0A%7D%7D
-);%0A%09%09r.pipe(res
+, function(error, response, body) %7B%0A%09console.log(response.headers)%0A%09res.end(response.headers.location)%0A%7D
 );%0A%09

Update code