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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-03-01 11:59:02 +00:00
|
|
|
var id = req.url.substring(1);
|
|
|
|
|
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', () => {
|
2022-03-01 11:59:02 +00:00
|
|
|
console.log(`[${time()}][${id}]${data}`);
|
2022-02-21 14:35:37 +00:00
|
|
|
res.writeHead(200);
|
|
|
|
res.end();
|
2022-02-20 00:30:32 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log("Listening on port 8080")
|
|
|
|
server.listen(8080);
|