Skip to content
Myr

add http verbs methods to Router

Before adoption: this commit came in with the history the project adopted, so no landing records it.

By having the method verbs available on the router, users can set up disjoint routers and organized paths easier. It is now possible to have a .js file export the router.middleware and attach these paths using an `app.use('/path', middleware)` call. This means that any routes written in the separate file do not need to have a full path hardcoded as they can be mounted by the application anywhere. This is already possible using `router.route(verb, args)` however is needlessly verbose without this patch.

authored by Roman Shtylman · committed by Roman Shtylman · parent 33eaa83 · Browse files · 2 files+15 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+15 added−3 removed

  • other:+15 added−3 removed

2 files+15 added−3 removed

modified:lib/router/index.js+9 added
2 unmodified lines
3 */45var Route = require('./route')6 , utils = require('../utils')7 , methods = require('methods')8 , debug = require('debug')('express:router')9 , parse = require('connect').utils.parseUrl;1011/**
248 unmodified lines
260 // add it261 (this.map[method] = this.map[method] || []).push(route);262 return this;263};264265methods.forEach(function(method){266 Router.prototype[method] = function(path){267 var args = [method].concat([].slice.call(arguments));268 this.route.apply(this, args);269 return this;270 };271});
modified:lib/application.js+6 added-3 removed
395 unmodified lines
396 return this;397};398399/**400 * Delegate `.VERB(...)` calls to `.route(VERB, ...)`.400 * Delegate `.VERB(...)` calls to `router.VERB(...)`.401 */402403methods.forEach(function(method){404 app[method] = function(path){405 if ('get' == method && 1 == arguments.length) return this.set(path);406 var args = [method].concat([].slice.call(arguments));406407 // if no router attacked yet, attach the router408 if (!this._usedRouter) this.use(this.router);408 this._router.route.apply(this._router, args);409410 // setup route411 this._router[method].apply(this._router, arguments);412 return this;413 };414});415
118 unmodified lines