1 path = require("path");
2 exec = require("child_process").exec;
3 http = require("http");
5 port = parseInt(process.env.PORT || 8000);
7 console.log('pid ' + process.pid);
10 for (var i = 0; i < 20*1024; i++) {
16 exec('git rev-list -1 HEAD', function (e, stdout) {
18 console.error("Problem executing: 'git rev-list -1 HEAD'");
21 rev = stdout.replace(/\s/g, '');
24 exec('uname -a', function (e, stdout) {
26 console.error("Problem executing: 'uname -a'");
29 uname = stdout.replace(/[\r\n]/g, '');
37 var server = http.createServer(function (req, res) {
38 var commands = req.url.split("/");
39 var command = commands[1];
41 var arg = commands[2];
42 var chunked = (commands[3] === "chunked");
45 if (command == "bytes") {
46 var n = parseInt(arg, 10)
48 throw "bytes called with n <= 0"
49 if (stored[n] === undefined) {
50 console.log("create stored[n]");
52 for (var i = 0; i < n; i++) {
58 } else if (command == "buffer") {
59 var n = parseInt(arg, 10)
60 if (n <= 0) throw new Error("bytes called with n <= 0");
61 if (storedBuffer[n] === undefined) {
62 console.log("create storedBuffer[n]");
63 storedBuffer[n] = new Buffer(n);
64 for (var i = 0; i < n; i++) {
65 storedBuffer[n][i] = "C".charCodeAt(0);
68 body = storedBuffer[n];
70 } else if (command == "quit") {
71 res.connection.server.close();
74 } else if (command == "fixed") {
77 } else if (command == "info") {
78 body = 'rev=' + rev + '\nuname="' + uname + '"\n';
86 res.writeHead(status, { "Content-Type": "text/plain",
87 "Transfer-Encoding": "chunked" });
89 var content_length = body.length.toString();
91 res.writeHead(status, { "Content-Type": "text/plain",
92 "Content-Length": content_length });
99 server.listen(port, function () {
100 console.log('Listening at http://127.0.0.1:'+port+'/');