Skip to content

Commit

Permalink
Log requests to static
Browse files Browse the repository at this point in the history
Closes: #434
  • Loading branch information
tshemsedinov committed Sep 11, 2023
1 parent 978c715 commit 5cad3e5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ class Transport extends EventEmitter {
this.send(packet, httpCode);
}

log(code) {
const { server, req, ip } = this;
const { console } = server;
const { url, method } = req;
const msg = `${ip}\t${method}\t${url}\t${code}`;
if (code >= 200 && code <= 299) console.debug(msg);
else console.error(msg);
}

send(obj, code = 200) {
const data = JSON.stringify(obj);
this.write(data, code, 'json');
Expand All @@ -124,7 +133,8 @@ class HttpTransport extends Transport {
}

write(data, httpCode = 200, ext = 'json', options = {}) {
const { res } = this;
this.log(httpCode);
const { res } = this;
if (res.writableEnded) return;
const streaming = data instanceof Readable;
let mimeType = MIME_TYPES.html;
Expand Down

0 comments on commit 5cad3e5

Please sign in to comment.