Skip to content

Instantly share code, notes, and snippets.

@pgr0ss
Created February 1, 2010 05:04
Show Gist options
  • Save pgr0ss/291468 to your computer and use it in GitHub Desktop.
Save pgr0ss/291468 to your computer and use it in GitHub Desktop.
var fs = require('fs'),
sys = require('sys'),
http = require('http');
http.createServer(function (req, res) {
checkBalanceFile(req, res);
}).listen(8000);
function checkBalanceFile(req, res) {
fs.stat("balance", function(err) {
if (err) {
setTimeout(function() {checkBalanceFile(req, res)}, 1000);
} else {
passThroughOriginalRequest(req, res);
}
});
}
function passThroughOriginalRequest(req, res) {
var request = http.createClient(2000, "localhost").request("GET", req.url, {});
request.addListener("response", function (response) {
res.writeHeader(response.statusCode, response.headers);
response.addListener("data", function (chunk) {
res.write(chunk);
});
response.addListener("end", function () {
res.close();
});
});
request.close();
}
sys.puts('Server running at http://127.0.0.1:8000/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment