-
-
Save davepacheco/3a4c0a97077274c0f921 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 mod_http = require('http'); | |
var server = mod_http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('Hello World\n'); | |
}); | |
server.listen(8081); |
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 mod_url = require('url'); | |
var mod_http = require('http'); | |
var parent_server; | |
function handleRequest(request, response) | |
{ | |
forward('127.0.0.1', 8081, request, response, function (err) { | |
if (err) | |
throw (err); | |
}); | |
} | |
function forward(child_host, child_port, request, response, callback) | |
{ | |
var subrequest; | |
subrequest = mod_http.request({ | |
host: child_host, | |
port: child_port, | |
path: request.url, | |
method: request.method, | |
agent: false | |
}, function (subresponse) { | |
response.statusCode = subresponse.statusCode; | |
subresponse.on('data', function (chunk) { response.write(chunk); }); | |
subresponse.on('end', function() { | |
response.end(); | |
// subresponse.removeAllListeners(); | |
// subresponse.destroy(); | |
// subrequest.removeAllListeners(); | |
// subrequest.destroy(); | |
}); | |
callback(); | |
}); | |
request.on('error', function (err) { return (callback(err)); }); | |
request.on('data', function (chunk) { subrequest.write(chunk); }); | |
request.on('end', function () { subrequest.end(); }); | |
}; | |
parent_server = mod_http.createServer(handleRequest); | |
parent_server.listen(8080); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment