How to use the methods.length function in methods

To help you get started, we’ve selected a few methods examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ivpusic / koa-routing / lib / route.js View on Github external
for (var j = 0; j < this._nesteds.length; j++) {
      if ((ret = this._nesteds[j].match(request))) {
        return ret;
      }
    }
  }

  // route is not matched
  return null;
};

/**
 * Define supported HTTP methods for Route object
 * and all failback method
 */
if (methods[methods.length - 1] !== 'all') {
  methods.push('all');
}

methods.forEach(function (METHOD) {
  Route.prototype[METHOD] = function () {
    var cbs = Array.prototype.slice.apply(arguments),
      that = this;

    cbs.forEach(function (cb) {
      util.isGenerator(cb, that);
    });

    this.handlers[METHOD.toUpperCase()] = cbs;
    return this;
  };
});
github nodesocket / quote-stream / node_modules / express / lib / router / index.js View on Github external
Router.prototype._optionsFor = function _optionsFor(path) {
  var options = [];

  for (var i = 0; i < methods.length; i++) {
    var method = methods[i];

    if (method === 'options') continue;

    var routes = this.map[method];

    // HEAD methods include GET routes
    if (!routes && method === 'head') {
      routes = this.map.get;
    }

    if (!routes) continue;

    for (var j = 0; j < routes.length; j++) {
      if (routes[j].match(path)) {
        options.push(method.toUpperCase());
github expressjs / express / test / Route.js View on Github external
it('should handle VERBS', function(done) {
      var count = 0;
      var route = new Route('/foo');
      var cb = after(methods.length, function (err) {
        if (err) return done(err);
        count.should.equal(methods.length);
        done();
      });

      route.all(function(req, res, next) {
        count++;
        next();
      });

      methods.forEach(function testMethod(method) {
        var req = { method: method, url: '/' };
        route.dispatch(req, {}, cb);
      });
    })
github koajs / router / test / lib / router.js View on Github external
it('registers route specific to HTTP verb', function () {
      var app = new Koa();
      var router = new Router();
      app.use(router.routes());
      methods.forEach(function (method) {
        router.should.have.property(method);
        router[method].should.be.type('function');
        router[method]('/', function () {});
      });
      router.stack.should.have.length(methods.length);
    });
github strapi / strapi / test / middlewares / router / router.js View on Github external
it('registers route specific to HTTP verb', function () {
      const app = new Koa();
      const router = strapi.middlewares.router();

      app.use(router.routes());

      methods.forEach(function (method) {
        router.should.have.property(method);
        router[method].should.be.type('function');
        router[method]('/', function * () {});
      });

      router.stack.should.have.length(methods.length);
    });
github expressjs / express / test / Route.js View on Github external
var cb = after(methods.length, function (err) {
        if (err) return done(err);
        count.should.equal(methods.length);
        done();
      });
github aredotna / ervell / node_modules / express / lib / application.js View on Github external
app.all = function all(path) {
  this.lazyrouter();

  var route = this._router.route(path);
  var args = slice.call(arguments, 1);

  for (var i = 0; i < methods.length; i++) {
    route[methods[i]].apply(route, args);
  }

  return this;
};
github codeforgeek / node-session / node_modules / express / lib / application.js View on Github external
app.all = function all(path) {
  this.lazyrouter();

  var route = this._router.route(path);
  var args = slice.call(arguments, 1);

  for (var i = 0; i < methods.length; i++) {
    route[methods[i]].apply(route, args);
  }

  return this;
};
github ILIAS-eLearning / ILIAS / Modules / Chatroom / chat / node_modules / express / lib / application.js View on Github external
app.all = function all(path) {
  this.lazyrouter();

  var route = this._router.route(path);
  var args = slice.call(arguments, 1);

  for (var i = 0; i < methods.length; i++) {
    route[methods[i]].apply(route, args);
  }

  return this;
};
github wesleytodd / nighthawk / lib / application.js View on Github external
Application.prototype.all = function (path) {
	var route = this.route(path);
	var args = Array.prototype.call(arguments, 1);

	for (var i = 0; i < methods.length; i++) {
		route[methods[i]].apply(route, args);
	}

	return this;
};