Introduce a flag for debug logging
This commit is contained in:
parent
2b133d3ed6
commit
171e91acce
|
@ -31,12 +31,19 @@ const port = parseInt(process.env.TRIVABBLE_PORT || "3000");
|
|||
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");
|
||||
|
||||
|
@ -569,7 +576,7 @@ function handleCommand(cmd, gameNumber, playerName, response) {
|
|||
var initialRackCount = countTiles(rack);
|
||||
var rackCount = countTiles(cmd.rack);
|
||||
|
||||
console.log(rack, cmd.rack);
|
||||
debuglog(rack, cmd.rack);
|
||||
|
||||
if (initialRackCount !== rackCount) {
|
||||
response.write(
|
||||
|
@ -680,7 +687,7 @@ function handleCommands(cmds, responseAndIsES) {
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
@ -704,7 +711,7 @@ function handleRequest(request, response) {
|
|||
request.url = "/index.html";
|
||||
}
|
||||
|
||||
console.log("Serving " + request.url);
|
||||
debuglog("Serving " + request.url);
|
||||
|
||||
fs.exists("." + request.url, function (exists) {
|
||||
if (exists) {
|
||||
|
@ -756,7 +763,7 @@ function handleRequest(request, response) {
|
|||
}
|
||||
|
||||
dateNow = Date.now();
|
||||
console.log("RECEIVED", request.url, post, isEventSource);
|
||||
debuglog("RECEIVED", request.url, post, isEventSource);
|
||||
handleCommands(post && JSON.parse(post), [response, isEventSource]);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue