Socket
Socket
Sign inDemoInstall

koa-route

Package Overview
Dependencies
5
Maintainers
9
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.4.2 to 3.0.0

36

index.js

@@ -0,1 +1,4 @@

'use strict';
/**

@@ -5,12 +8,12 @@ * Module dependencies.

var pathToRegexp = require('path-to-regexp');
var debug = require('debug')('koa-route');
var methods = require('methods');
const pathToRegexp = require('path-to-regexp');
const debug = require('debug')('koa-route');
const methods = require('methods');
methods.forEach(function(method){
exports[method] = create(method);
module.exports[method] = create(method);
});
exports.del = exports.delete;
exports.all = create();
module.exports.del = module.exports.delete;
module.exports.all = create();

@@ -21,22 +24,21 @@ function create(method) {

return function(path, fn, opts){
var re = pathToRegexp(path, opts);
const re = pathToRegexp(path, opts);
debug('%s %s -> %s', method || 'ALL', path, re);
return function *(next){
var m;
return function (ctx, next){
// method
if (!matches(this, method)) return yield* next;
if (!matches(ctx, method)) return next();
// path
if (m = re.exec(this.path)) {
var args = m.slice(1).map(decode);
debug('%s %s matches %s %j', this.method, path, this.path, args);
const m = re.exec(ctx.path);
if (m) {
const args = m.slice(1).map(decode);
debug('%s %s matches %s %j', ctx.method, path, ctx.path, args);
args.unshift(ctx);
args.push(next);
yield* fn.apply(this, args);
return;
return Promise.resolve(fn.apply(ctx, args));
}
// miss
return yield* next;
return next();
}

@@ -43,0 +45,0 @@ }

@@ -5,3 +5,3 @@ {

"repository": "koajs/route",
"version": "2.4.2",
"version": "3.0.0",
"keywords": [

@@ -19,3 +19,3 @@ "koa",

"istanbul-harmony": "0",
"koa": "0",
"koa": "^2.0.0-alpha.3",
"mocha": "^2.2.5",

@@ -22,0 +22,0 @@ "should": "*",

@@ -26,4 +26,4 @@ # koa-route

var _ = require('koa-route');
var koa = require('koa');
var app = koa();
var Koa = require('koa');
var app = new Koa();

@@ -37,11 +37,11 @@ var db = {

var pets = {
list: function *(){
list: (ctx) => {
var names = Object.keys(db);
this.body = 'pets: ' + names.join(', ');
ctx.body = 'pets: ' + names.join(', ');
},
show: function *(name){
show: (ctx, name) => {
var pet = db[name];
if (!pet) return this.throw('cannot find that pet', 404);
this.body = pet.name + ' is a ' + pet.species;
if (!pet) return ctx.throw('cannot find that pet', 404);
ctx.body = pet.name + ' is a ' + pet.species;
}

@@ -48,0 +48,0 @@ };

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc