| 949 | const route = typeof arguments[0] === 'string' ? args.shift() : null |
| 950 | |
| 951 | const handler = function(req, res, next) { |
| 952 | if (!(req.method && req.method.toLowerCase() === verb)) { |
| 953 | next() |
| 954 | } |
| 955 | |
| 956 | // push the next route on to the bottom of callback stack in case none of these callbacks send a response |
| 957 | args.push(next) |
| 958 | |
| 959 | const doCallbacks = function(i) { |
| 960 | return function(err) { |
| 961 | if (err) return next(err) |
| 962 | |
| 963 | args[i](req, res, doCallbacks(++i)) |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | doCallbacks(0)() |
| 968 | } |
| 969 | |
| 970 | // if there is a route provided, only call for matching requests |
| 971 | if (route) { |