X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fdingus.js;h=d8eed919a6fd992b463f2fc154edc034ff7dfdb2;hb=a90b9c1b279773c225560aa3ae5f5f21424ec420;hp=943aa2f91e7bfc141960b35182bbbc23ef816f16;hpb=953c58b691c50950e7c5a87966b5ea56ef6ffa95;p=squeep-api-dingus diff --git a/lib/dingus.js b/lib/dingus.js index 943aa2f..d8eed91 100644 --- a/lib/dingus.js +++ b/lib/dingus.js @@ -60,7 +60,6 @@ class Dingus { ]; this.logger = logger; - common.ensureLoggerLevels(this.logger); } @@ -139,9 +138,9 @@ class Dingus { */ _getAddress(req) { // TODO: RFC7239 Forwarded support - const address = (this.trustProxy && req && req.getHeader(Enum.Header.XForwardedFor)) || - (this.trustProxy && req && req.getHeader(Enum.Header.XRealIP)) || - (req && req.connection && req.connection.remoteAddress) || + const address = (this.trustProxy && req?.getHeader(Enum.Header.XForwardedFor)) || + (this.trustProxy && req?.getHeader(Enum.Header.XRealIP)) || + (req?.connection?.remoteAddress) || ''; return address.split(/\s*,\s*/u)[0]; } @@ -153,8 +152,8 @@ class Dingus { */ _getProtocol(req) { // TODO: RFC7239 Forwarded support - const protocol = (this.trustProxy && req && req.getHeader(Enum.Header.XForwardedProto)) || - ((req && req.connection && req.connection.encrypted) ? 'https' : 'http'); + const protocol = (this.trustProxy && req?.getHeader(Enum.Header.XForwardedProto)) || + ((req?.connection?.encrypted) ? 'https' : 'http'); return protocol.split(/\s*,\s*/u)[0]; } @@ -539,7 +538,7 @@ class Dingus { // We will not deal with any subdirs, nor any dot-files. // (Note that we could not deal with subdirs even if we wanted, due to simple router matching scheme.) if (fileName.indexOf(path.sep) >= 0 - || fileName.charAt(0) === '.') { + || fileName.startsWith('.')) { this.logger.debug(_scope, 'rejected filename', { fileName }); return this.handlerNotFound(req, res, ctx); } @@ -652,7 +651,7 @@ class Dingus { res.setHeader(Enum.Header.ContentType, Enum.ContentType.TextPlain); } - if (err && err.statusCode) { + if (err?.statusCode) { res.statusCode = err.statusCode; body = this.renderError(res.getHeader(Enum.Header.ContentType), err); this.logger.debug(_scope, 'handler error', { err, req, res, ctx });