From a558d306ba48bfa9acea401a47fe9465bd9eb88f Mon Sep 17 00:00:00 2001 From: dead-horse Date: Wed, 24 Jan 2018 22:27:02 +0800 Subject: [PATCH] expose the Application::handleRequest method --- lib/application.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/application.js b/lib/application.js index 8b6a78b..02c7df0 100644 --- a/lib/application.js +++ b/lib/application.js @@ -130,15 +130,19 @@ app.callback = function(){ if (!this.listeners('error').length) this.on('error', this.onerror); return function handleRequest(req, res){ - res.statusCode = 404; var ctx = self.createContext(req, res); - onFinished(res, ctx.onerror); - fn.call(ctx).then(function handleResponse() { - respond.call(ctx); - }).catch(ctx.onerror); + app.handleRequest(ctx, fn); } }; +app.handleRequest = function(ctx, fnMiddleware){ + ctx.res.statusCode = 404; + onFinished(ctx.res, ctx.onerror); + fnMiddleware.call(ctx).then(function handleResponse() { + respond.call(ctx); + }).catch(ctx.onerror); +}; + /** * Initialize a new context. *