rill[name] = function (pathname) { var offset = typeof pathname === 'string' ? 1 : 0 var fn = chain(slice.call(arguments, offset)) if (offset === 1) return this.at(pathname, matchMethod) return this.use(matchMethod) function matchMethod (ctx, next) { if (ctx.req.method !== method) return next() return fn(ctx, next) } }
rill.handler = function handler () { var fn = chain(this.stack) return function handleIncommingMessage (req, res) { res.statusCode = 404 var ctx = new Context(req, res) fn(ctx) .catch(handleError) .then(finish) function handleError (err) { if (Number(ctx.res.status) === 404) { ctx.res.status = 500 } if (!(err instanceof HttpError)) { console && console.error && console.error(err.stack || err) } } function finish () { respond(ctx) } } }