-
-
Save jixunmoe/14bc2ce98144e3b2aaa81cf67f0a0782 to your computer and use it in GitHub Desktop.
express@4.17.1 patch to support async middleware/handler.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/node_modules/express/lib/router/layer.js b/node_modules/express/lib/router/layer.js | |
index 4dc8e86..aabcde0 100644 | |
--- a/node_modules/express/lib/router/layer.js | |
+++ b/node_modules/express/lib/router/layer.js | |
@@ -59,7 +59,7 @@ function Layer(path, options, fn) { | |
* @api private | |
*/ | |
-Layer.prototype.handle_error = function handle_error(error, req, res, next) { | |
+Layer.prototype.handle_error = async function handle_error(error, req, res, next) { | |
var fn = this.handle; | |
if (fn.length !== 4) { | |
@@ -68,7 +68,7 @@ Layer.prototype.handle_error = function handle_error(error, req, res, next) { | |
} | |
try { | |
- fn(error, req, res, next); | |
+ await fn(error, req, res, next); | |
} catch (err) { | |
next(err); | |
} | |
@@ -83,7 +83,7 @@ Layer.prototype.handle_error = function handle_error(error, req, res, next) { | |
* @api private | |
*/ | |
-Layer.prototype.handle_request = function handle(req, res, next) { | |
+Layer.prototype.handle_request = async function handle(req, res, next) { | |
var fn = this.handle; | |
if (fn.length > 3) { | |
@@ -92,7 +92,7 @@ Layer.prototype.handle_request = function handle(req, res, next) { | |
} | |
try { | |
- fn(req, res, next); | |
+ await fn(req, res, next); | |
} catch (err) { | |
next(err); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment