lib/layer.js
function Layer(path, methods, middleware, opts) {
  this.opts = opts || {};
  this.name = this.opts.name || null;
  this.methods = [];
  this.paramNames = [];
  this.stack = Array.isArray(middleware) ? middleware : [middleware];

  methods.forEach(function(method) {
    var l = this.methods.push(method.toUpperCase());
    if (this.methods[l-1] === 'GET') {
      this.methods.unshift('HEAD');
    }
  }, this);

  // ensure middleware is a function
  this.stack.forEach(function(fn) {
    var type = (typeof fn);
    if (type !== 'function') {
      throw new Error(
        methods.toString() + " `" + (this.opts.name || path) +"`: `middleware` "
        + "must be a function, not `" + type + "`"
      );
    }
  }, this);

  this.path = path;
  this.regexp = pathToRegExp(path, this.paramNames, this.opts);

  debug('defined route %s %s', this.methods, this.opts.prefix + this.path);
}
function Layer(path, methods, middleware, opts) {
  this.opts = opts || {};
  this.name = this.opts.name || null;
  this.methods = [];
  this.paramNames = [];
  this.stack = Array.isArray(middleware) ? middleware : [middleware];

  methods.forEach(function(method) {
    var l = this.methods.push(method.toUpperCase());
    if (this.methods[l-1] === 'GET') {
      this.methods.unshift('HEAD');
    }
  }, this);

  // ensure middleware is a function
  this.stack.forEach(function(fn) {
    var type = (typeof fn);
    if (type !== 'function') {
      throw new Error(
        methods.toString() + " `" + (this.opts.name || path) +"`: `middleware` "
        + "must be a function, not `" + type + "`"
      );
    }
  }, this);

  this.path = path;
  this.regexp = pathToRegExp(path, this.paramNames, this.opts);

  debug('defined route %s %s', this.methods, this.opts.prefix + this.path);
}
function Layer ( path , methods , middleware , opts ) { this . opts = opts || { } ; this . name = this . opts . name || null ; this . methods = [ ] ; this . paramNames = [ ] ; this . stack = Array . isArray ( middleware ) ? middleware : [ middleware ] ; methods . forEach ( function ( method ) { var l = this . methods . push ( method . toUpperCase ( ) ) ; if ( this . methods [ l - 1 ] === 'GET' ) { this . methods . unshift ( 'HEAD' ) ; } } , this ) ; // ensure middleware is a function this . stack . forEach ( function ( fn ) { var type = ( typeof fn ) ; if ( type !== 'function' ) { throw new Error ( methods . toString ( ) + " `" + ( this . opts . name || path ) + "`: `middleware` " + "must be a function, not `" + type + "`" ) ; } } , this ) ; this . path = path ; this . regexp = pathToRegExp ( path , this . paramNames , this . opts ) ; debug ( 'defined route %s %s' , this . methods , this . opts . prefix + this . path ) ; }
Initialize a new routing Layer with given `method`, `path`, and `middleware`.

@param {String|RegExp} path Path string or regular expression.
@param {Array} methods Array of HTTP verbs.
@param {Array} middleware Layer callback/middleware or series of.
@param {Object=} opts
@param {String=} opts.name route name
@param {String=} opts.sensitive case sensitive (default: false)
@param {String=} opts.strict require the trailing slash (default: false)
@returns {Layer}
@private
Initialize a new routing Layer with given method path and middleware .