Skip to content

Instantly share code, notes, and snippets.

@marinkovci
Created February 14, 2012 06:05
Show Gist options
  • Save marinkovci/1824150 to your computer and use it in GitHub Desktop.
Save marinkovci/1824150 to your computer and use it in GitHub Desktop.
var http = require("http");
var url = require("url");
var requestUrl = require("request");
var port = process.env.PORT || 1856;
http.createServer(function(request, response) {
// request module works from here
if (request.url.substr(0, 4) == '/ws/') {
var r = requestUrl('http://xxx.iriscouch.com:5984' + request.url);
request.pipe(r);
r.pipe(response);
return;
}
var postData = "";
var pathname = url.parse(request.url).pathname;
request.setEncoding("utf8");
request.addListener("data", function(postDataChunk) {
postData += postDataChunk;
});
request.addListener("end", function() {
//route(handle, pathname, request, response, postData);
console.log ('CALL:', 'http://xxx.iriscouch.com:5984' + request.url);
return;
// request module times out from here
var r = requestUrl('http://tesla.iriscouch.com:5984' + request.url);
request.pipe(r);
r.pipe(response);
});
}).listen(port);
console.log('Server started on port', port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment