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