Permalink
Browse files

Merge pull request #1454 from shtylman/router-http-methods

add http verbs methods to Router
  • Loading branch information...
2 parents 64a2349 + e4907ce commit 618484a4fe35763d32e70613fea9cc01e6d564fe @tj tj committed Dec 28, 2012
Showing with 15 additions and 3 deletions.
  1. +6 −3 lib/application.js
  2. +9 −0 lib/router/index.js
View
@@ -397,15 +397,18 @@ app.configure = function(env, fn){
};
/**
- * Delegate `.VERB(...)` calls to `.route(VERB, ...)`.
+ * 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 args = [method].concat([].slice.call(arguments));
+
+ // if no router attacked yet, attach the router
if (!this._usedRouter) this.use(this.router);
- this._router.route.apply(this._router, args);
+
+ // setup route
+ this._router[method].apply(this._router, arguments);
return this;
};
});
View
@@ -4,6 +4,7 @@
var Route = require('./route')
, utils = require('../utils')
+ , methods = require('methods')
, debug = require('debug')('express:router')
, parse = require('connect').utils.parseUrl;
@@ -260,3 +261,11 @@ Router.prototype.route = function(method, path, callbacks){
(this.map[method] = this.map[method] || []).push(route);
return this;
};
+
+methods.forEach(function(method){
+ Router.prototype[method] = function(path){
+ var args = [method].concat([].slice.call(arguments));
+ this.route.apply(this, args);
+ return this;
+ };
+});

0 comments on commit 618484a

Please sign in to comment.