allow null terminating handler
This commit is contained in:
parent
391775b702
commit
664127cdbc
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user