Created
February 14, 2012 06:05
-
-
Save marinkovci/1824150 to your computer and use it in GitHub Desktop.
This file contains 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 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