Simplify app.all and app.VERB
- Dominant language
- JavaScript
- Stars
- 69.5k
- Forks
- 25k
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 9
Description
https://github.com/strongloop/express/blob/5.0/lib/application.js
Currently:
``` js
/**
* Delegate `.VERB(...)` calls to `router.VERB(...)`.
*/
methods.forEach(function(method){
app[method] = function(path){
if ('get' == method && 1 == arguments.length) return this.set(path);
var route = this.route(path);
route[method].apply(route, slice.call(arguments, 1));
return this;
};
});
/**
* Special-cased "all" method, applying the given route `path`,
* middleware, and callback to _every_ HTTP method.
*
* @param {String} path
* @param {Function} ...
* @return {app} for chaining
* @api public
*/
app.all = function(path){
var route = this.route(path);
var args = slice.call(arguments, 1);
methods.forEach(function(method){
route[method].apply(route, args);
});
return this;
};
```
But the following simplified code does exactly the same (in fact `lib/Router/index.js` does it):
``` js
/**
* Delegate `.all(...)` and `.VERB(...)` calls to `Router#all(...)` and `Router#VERB(...)`.
*/
methods.concat('all').forEach(function(method){
app[method] = function(path){
if ('get' == method && 1 == arguments.length) return this.set(path);
var route = this.route(path);
route[method].apply(route, slice.call(arguments, 1));
return this;
};
});
```
Contributor guide
Assessment
This issue has not been assessed yet.