Created
February 1, 2010 05:04
-
-
Save pgr0ss/291468 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 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