Skip to content

Commit

Permalink
notFound method to have access to middleware.
Browse files Browse the repository at this point in the history
  • Loading branch information
aichholzer committed Jun 16, 2019
1 parent 077884b commit b7f1571
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions packages/rayo/index.js
Expand Up @@ -56,29 +56,24 @@ class Rayo extends Bridge {
}

dispatch(req, res) {
const through = this.t;

const parsedUrl = parseurl(req);
req.ip = ip(req);
req.pathname = parsedUrl.pathname;
req.query = parse(parsedUrl.query);

let stack;
const route = this.fetch(req.method, parsedUrl.pathname);
if (!route) {
return this.step(
req,
res,
through.concat([
this.notFound
? this.notFound
: () =>
end(req, res, 404, `${req.method} ${parsedUrl.pathname} is undefined.`)
])
);
stack = [
this.notFound ||
(() => end(req, res, 404, `${req.method} ${parsedUrl.pathname} is undefined.`))
];
} else {
req.params = route.params;
({ stack } = route);
}

req.params = route.params;
return this.step(req, res, through.concat(route.stack));
return this.step(req, res, this.t.concat(stack));
}

step(req, res, stack, error = null, statusCode = 400) {
Expand Down

0 comments on commit b7f1571

Please sign in to comment.