diff --git a/src/server/Server.js b/src/server/Server.js index 186d45c..4204a00 100644 --- a/src/server/Server.js +++ b/src/server/Server.js @@ -112,7 +112,7 @@ class Server extends EventEmitter { logRequest (req, res, next) { res.once('finish', () => { - this.logger[res.statusCode === 401 ? 'unauthorised' : 'access'](`[${req.get('X-Forwarded-For') || req.socket.remoteAddress}] [STATUS: ${res.statusCode}] Request to ${req.route?.path || req.path}`); + this.logger[res.statusCode === 401 ? 'unauthorised' : 'access'](`[${req.get('X-Forwarded-For') || req.socket.remoteAddress}] [STATUS: ${res.statusCode}] [${req.user?.username || 'UNAUTHENTICATED'}] Request to ${req.route?.path || req.path}`); }); next(); } diff --git a/src/server/interfaces/Endpoint.js b/src/server/interfaces/Endpoint.js index a25e353..8a23a3b 100644 --- a/src/server/interfaces/Endpoint.js +++ b/src/server/interfaces/Endpoint.js @@ -37,7 +37,10 @@ class Endpoint { this.subpaths = [ ...this._subpaths, ...this.subpaths ]; for (const [ sub, method, cb, mw = [] ] of this.subpaths) { if (typeof method !== 'string') throw new Error(`Invalid method parameter type in Endpoint ${this.name} subpath ${sub}`); - this.server.app[method](this.path + sub, ...this.middleware, ...mw, cb); + if (!this.middleware.length && !mw.length && !cb) throw new Error(`Cannot have endpoint with no handler and no middleware, expecting at least one to be defined`); + const args = [ this.path + sub, ...this.middleware, ...mw ]; + if (cb) args.push(cb); // Sometimes (such as login endpoints) we don't necessarily want an explicit terminating handler, rather the middleware takes care of it + this.server.app[method](...args); } }