Skip to content

Instantly share code, notes, and snippets.

@jixunmoe
Last active February 5, 2020 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jixunmoe/14bc2ce98144e3b2aaa81cf67f0a0782 to your computer and use it in GitHub Desktop.
Save jixunmoe/14bc2ce98144e3b2aaa81cf67f0a0782 to your computer and use it in GitHub Desktop.
express@4.17.1 patch to support async middleware/handler.
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