Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}
};
}
else { // serve HTML UI
request.onEnd = function () {
request.onWriteReady = function () { request.writeBody(chatui.htmlForMultitenancy, true); };
request.writeHeaders(200, "OK", { "Content-type": "text/html", "Content-length": chatui.htmlForMultitenancy.length.toString(), "Cache-Control": "no-cache" }, false);
}
}
request.readMore();
}
http.createServer({ url: "http://*:80/chat/" + programId, onNewRequest: chatHttpHandler }).start(); // start message and UI server
scheduler.later(publishUsageUpdate, 10000, true); // publish usage statistics every 10 seconds
scheduleDanteQuote(); // schedule a post of Dante's Divine Comedy (Cante I, The Inferno)
publishUsageUpdate(); // publish once on startup to ensure every new client receives an immediate update
tracing.write("Chat started at http://localhost/chat/" + programId);
request.onEnd = function (event) {
if ("POST" === request.verb) { // publish message
publishMessage(bufferedBody, "text/plain");
request.writeHeaders(200, "OK", {}, true);
}
else { // HTTP long poll for messages
if (!releasePoll(request)) {
polls[request.requestSlot] = {
request: request,
timer: scheduler.later(function () { timeoutPoll(request.requestSlot); }, 15000)
};
}
}
};
}
function scheduleDanteQuote() {
scheduler.later(
function () {
publishMessage(dante.getNextLine(), "text/plain");
scheduleDanteQuote();
},
200);
//5000 + Math.floor(4000 * Math.random()));
}