Comparing version 3.0.5 to 3.0.6
@@ -110,2 +110,11 @@ 'use strict'; | ||
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) { | ||
@@ -128,6 +137,11 @@ const data = JSON.stringify(obj); | ||
write(data, httpCode = 200, ext = 'json', options = {}) { | ||
this.log(httpCode); | ||
const { res } = this; | ||
if (res.writableEnded) return; | ||
const streaming = data instanceof Readable; | ||
const mimeType = MIME_TYPES[ext] || MIME_TYPES.html; | ||
let mimeType = MIME_TYPES.html; | ||
if (httpCode === 200) { | ||
const fileType = MIME_TYPES[ext]; | ||
if (fileType) mimeType = fileType; | ||
} | ||
const headers = { ...HEADERS, 'Content-Type': mimeType }; | ||
@@ -134,0 +148,0 @@ if (httpCode === 206) { |
{ | ||
"name": "metacom", | ||
"version": "3.0.5", | ||
"version": "3.0.6", | ||
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "Communication protocol for Metarhia stack with rpc, events, binary streams, memory and db access", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54824
1617