cc-haxe/tools/console.js

70 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2022-02-20 00:30:32 +00:00
const http = require('http');
function time() {
let now = new Date();
2022-02-21 14:35:37 +00:00
return `${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, 0)}:${now.getSeconds().toString().padStart(2, 0)}`;
2022-02-20 00:30:32 +00:00
}
2024-08-16 22:47:15 +00:00
const Reset = "\x1b[0m";
const FgBlack = "\x1b[30m"
const FgRed = "\x1b[31m"
const FgGreen = "\x1b[32m"
const FgYellow = "\x1b[33m"
const FgBlue = "\x1b[34m"
const FgMagenta = "\x1b[35m"
const FgCyan = "\x1b[36m"
const FgWhite = "\x1b[37m"
const FgGray = "\x1b[90m"
function log(id, lvl, msg) {
var logLvl = "UNKN";
switch (lvl) {
case "0":
logLvl = "INFO";
break;
case "1":
logLvl = FgYellow + "WARN" + Reset;
break;
case "2":
logLvl = FgRed + "ERRO" + Reset;
break;
case "3":
logLvl = FgGray + "DEBG" + Reset;
break;
case "4":
logLvl = FgWhite + "SILY" + Reset;
break;
}
console.log(`(${id})[${logLvl}]${msg}`);
}
2022-02-21 14:35:37 +00:00
const server = http.createServer((req, res) => {
2022-02-20 00:30:32 +00:00
2022-02-21 14:35:37 +00:00
if (req.method != "POST") {
2022-02-20 00:30:32 +00:00
res.writeHead(400);
return;
}
2024-08-16 22:47:15 +00:00
var urlParts = req.url.split("/");
var id = urlParts[2];
var lvl = urlParts[3];
2022-03-01 11:59:02 +00:00
2022-02-20 00:30:32 +00:00
let data = "";
req.on('data', chunk => {
2022-02-21 14:35:37 +00:00
data += chunk;
2022-02-20 00:30:32 +00:00
})
req.on('end', () => {
2024-08-16 22:47:15 +00:00
log(id, lvl, data);
2022-02-21 14:35:37 +00:00
res.writeHead(200);
res.end();
2022-02-20 00:30:32 +00:00
})
});
2024-08-16 22:47:15 +00:00
console.log("Webconsole running on port 8080");
2022-02-20 00:30:32 +00:00
server.listen(8080);