Skip to content

Instantly share code, notes, and snippets.

@jixunmoe

jixunmoe/express+4.17.1.patch Secret

Last active Feb 5, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.