Socket
Socket
Sign inDemoInstall

koa-router

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-router - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

8

lib/resource.js

@@ -59,4 +59,8 @@ /**

var baseTrailing = base[base.length-1] == '/' ? base : base + '/';
// Determine the arguments to create the route for this action
switch (name) {
case 'options':
args = ['OPTIONS', base, action];
break;
case 'index':

@@ -84,3 +88,7 @@ args = ['GET', base, action];

break;
// Gracefully ignore unsupported controller actions
default:
return this;
}
// Create the route for this action

@@ -87,0 +95,0 @@ var route = Object.create(Route.prototype);

2

package.json

@@ -9,3 +9,3 @@ {

"author": "Alex Mingoia <talk@alexmingoia.com>",
"version": "2.1.0",
"version": "2.2.0",
"keywords": [

@@ -12,0 +12,0 @@ "koa",

@@ -12,3 +12,3 @@ /**

describe('Resource', function() {
it('should be exposed using `app.resource()`', function(done) {
it('creates `app.resource()` alias', function(done) {
var app = koa();

@@ -21,3 +21,3 @@ app.use(Router(app));

it('should create new resource', function(done) {
it('creates new resource', function(done) {
var app = koa();

@@ -41,3 +41,3 @@ app.use(Router(app));

it('should skip non functions', function(done) {
it('skips non-functions', function(done) {
var app = koa();

@@ -62,3 +62,3 @@ app.use(Router(app));

it('should nest resources', function(done) {
it('nests resources', function(done) {
var app = koa();

@@ -65,0 +65,0 @@ var router = new Router(app);

@@ -15,3 +15,3 @@ /**

describe('Router', function() {
it('should create new router with koa app', function(done) {
it('creates new router with koa app', function(done) {
var app = koa();

@@ -23,3 +23,3 @@ var router = new Router(app);

it('should expose middleware factory', function(done) {
it('exposes middleware factory', function(done) {
var app = koa();

@@ -35,3 +35,3 @@ var router = new Router(app);

it('should match corresponding requests', function(done) {
it('matches corresponding requests', function(done) {
var app = koa();

@@ -66,3 +66,3 @@ app.use(Router(app));

it('should support generators', function(done) {
it('supports generators for route middleware', function(done) {
var app = koa();

@@ -97,62 +97,88 @@ app.use(Router(app));

it('should provide `app.verb()` methods', function(done) {
var app = koa();
var router = new Router(app);
app.use(router.middleware());
methods.forEach(function(method) {
app.should.have.property(method);
app[method].should.be.a('function');
var route = app[method]('/', function *() {});
router.routes[method].should.include(route);
describe('Router#[verb]()', function() {
it('registers route specific to HTTP verb', function(done) {
var app = koa();
var router = new Router(app);
app.use(router.middleware());
methods.forEach(function(method) {
app.should.have.property(method);
app[method].should.be.a('function');
var route = app[method]('/', function *() {});
router.routes[method].should.include(route);
});
done();
});
done();
});
it('should provide `app.all()` for routing all verbs', function(done) {
var app = koa();
var router = new Router(app);
app.use(router.middleware());
var route = app.all('/', function *(next) {
this.status = 204;
describe('Router#all()', function() {
it('registers route for all HTTP verbs', function(done) {
var app = koa();
var router = new Router(app);
app.use(router.middleware());
var route = app.all('/', function *(next) {
this.status = 204;
});
methods.forEach(function(method) {
router.should.have.property('routes');
router.routes.should.have.property(method);
router.routes[method].should.include(route);
});
done();
});
methods.forEach(function(method) {
router.should.have.property('routes');
router.routes.should.have.property(method);
router.routes[method].should.include(route);
});
done();
});
it('should provide `app.map()` for routing multiple verbs', function(done) {
var app = koa();
var router = new Router(app);
app.use(router.middleware());
app.should.have.property('map');
app.map.should.be.a('function');
var route = app.map(['get', 'post'], '/', function *() {});
router.routes.get.should.include(route);
router.routes.post.should.include(route);
done();
describe('Router#map()', function() {
it('registers route specific to array of HTTP verbs', function(done) {
var app = koa();
var router = new Router(app);
app.use(router.middleware());
app.should.have.property('map');
app.map.should.be.a('function');
var route = app.map(['get', 'post'], '/', function *() {});
router.routes.get.should.include(route);
router.routes.post.should.include(route);
done();
});
});
it('should provide `app.redirect()` for redirect routes', function(done) {
var app = koa();
var router = new Router(app);
app.use(router.middleware());
app.should.have.property('redirect');
app.redirect.should.be.a('function');
var route = app.redirect('/source', '/destination', 302);
router.routes.get.should.include(route);
done();
describe('Router#redirect()', function() {
it('registers redirect routes', function(done) {
var app = koa();
var router = new Router(app);
app.use(router.middleware());
app.should.have.property('redirect');
app.redirect.should.be.a('function');
var route = app.redirect('/source', '/destination', 302);
router.routes.get.should.include(route);
done();
});
});
it('should provide `app.resource()` for resource routing', function(done) {
var app = koa();
var router = new Router(app);
app.use(router.middleware());
app.should.have.property('resource');
app.redirect.should.be.a('function');
app.resource('forums', { index: function *() {}, show: function*() {} });
done();
describe('Router#resource()', function() {
it('registers routes for a resource', function(done) {
var app = koa();
var router = new Router(app);
app.use(router.middleware());
app.should.have.property('resource');
app.resource.should.be.a('function');
app.resource('forums', {
'options': function *() {},
'index': function *() {},
'show': function*() {},
'new': function*() {},
'create': function*() {},
'show': function*() {},
'read': function*() {},
'edit': function*() {},
'update': function*() {},
'destroy': function*() {},
});
router.routes.options.length.should.equal(1);
router.routes.get.length.should.equal(5);
router.routes.put.length.should.equal(1);
router.routes.post.length.should.equal(1);
router.routes['delete'].length.should.equal(1);
done();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc