const SAVE_TIMEOUT = 5000;
const KEEP_ALIVE = 30000;
-const DEV_ENABLE_SERVING_FILES = (process.env.DEV_ENABLE_SERVING_FILES || "").toLowerCase() === "true";
+function envTrue(name) {
+ return (process.env[name] || "").toLowerCase() === "true";
+}
+
+const DEV_ENABLE_SERVING_FILES = envTrue('DEV_ENABLE_SERVING_FILES');
+const DEBUG_LOG = DEV_ENABLE_SERVING_FILES || envTrue('DEBUG_LOG');
if (DEV_ENABLE_SERVING_FILES) {
console.log("DEV_ENABLE_SERVING_FILES: Serving files in the current directory. Please never do this on a production server, this is for development purposes only.");
}
+var debuglog = DEBUG_LOG ? console.log.bind(console) : () => null;
+
var http = require("http");
var fs = require("fs");
var initialRackCount = countTiles(rack);
var rackCount = countTiles(cmd.rack);
- console.log(rack, cmd.rack);
+ debuglog(rack, cmd.rack);
if (initialRackCount !== rackCount) {
response.write(
response.end("]");
if (games[cmds.gameNumber]) {
- console.log("pendingEvents COMMIT", games[cmds.gameNumber].pendingEvents);
+ debuglog("pendingEvents COMMIT", games[cmds.gameNumber].pendingEvents);
games[cmds.gameNumber].commit();
}
}
request.url = "/index.html";
}
- console.log("Serving " + request.url);
+ debuglog("Serving " + request.url);
fs.exists("." + request.url, function (exists) {
if (exists) {
}
dateNow = Date.now();
- console.log("RECEIVED", request.url, post, isEventSource);
+ debuglog("RECEIVED", request.url, post, isEventSource);
handleCommands(post && JSON.parse(post), [response, isEventSource]);
});
}