Skip to content

Commit

Permalink
fix: add named function for request and response handlers
Browse files Browse the repository at this point in the history
cherry-pick #804
  • Loading branch information
fengmk2 committed Aug 31, 2016
1 parent e4c0a53 commit ddf594b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,18 @@ module.exports = class Application extends Emitter {

callback() {
const fn = compose(this.middleware);
const self = this;

if (!this.listeners('error').length) this.on('error', this.onerror);

return (req, res) => {
return function handleRequest(req, res) {
res.statusCode = 404;
const ctx = this.createContext(req, res);
const ctx = self.createContext(req, res);
const onerror = err => ctx.onerror(err);
onFinished(res, onerror);
fn(ctx).then(() => respond(ctx)).catch(onerror);
fn(ctx).then(function handleResponse() {
respond(ctx);
}).catch(onerror);
};
}

Expand Down

0 comments on commit ddf594b

Please sign in to comment.