Better notFoundGenerator

This commit is contained in:
Bryan Ashby 2018-04-24 20:07:02 -06:00
parent 69ced917f3
commit 0b77c1f79e
1 changed files with 7 additions and 8 deletions

View File

@ -131,18 +131,17 @@ exports.getModule = class GopherModule extends ServerModule {
} }
routeRequest(selector, socket) { routeRequest(selector, socket) {
let generator;
let match; let match;
for(let [regex, gen] of this.routes) { for(let [regex, gen] of this.routes) {
match = selector.match(regex); match = selector.match(regex);
if(match) { if(match) {
generator = gen; return gen(match, res => {
break; return socket.end(`${res}`);
});
} }
} }
generator = generator || this.notFoundGenerator.bind(this); this.notFoundGenerator(selector, res => {
generator(match, res => { return socket.end(`${res}`);
socket.end(`${res}`);
}); });
} }
@ -169,8 +168,8 @@ exports.getModule = class GopherModule extends ServerModule {
}); });
} }
notFoundGenerator(selectorMatch, cb) { notFoundGenerator(selector, cb) {
this.log.trace( { selector : selectorMatch[0] }, 'Serving not found content'); this.log.trace( { selector }, 'Serving not found content');
return cb('Not found'); return cb('Not found');
} }