lark-router
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -8,5 +8,5 @@ /** | ||
const events = require('events'); | ||
const path2regexp = require('path-to-regexp'); | ||
const methods = require('./methods'); | ||
const Route = require('./Route'); | ||
const Switcher = require('./Switcher'); | ||
@@ -21,3 +21,3 @@ | ||
route(method, route, handler) { | ||
route(method, routePath, handler) { | ||
const typeofMethod = typeof method; | ||
@@ -29,15 +29,15 @@ assert('string' === typeofMethod, `Method should be a string, ${typeofMethod} given`); | ||
assert('string' === typeof route || route instanceof RegExp, | ||
`Route should be a string or a regular expression, ${typeof route} given`); | ||
assert('string' === typeof routePath || routePath instanceof RegExp, | ||
`Route should be a string or a regular expression, ${typeof routePath} given`); | ||
let regexp = null; | ||
let route = null; | ||
if (handler instanceof Router) { | ||
regexp = path2regexp(route, null, { end: false }); | ||
route = new Route(routePath, { end: false }); | ||
handler = handler.switcher; | ||
} | ||
else { | ||
regexp = path2regexp(route); | ||
route = new Route(routePath); | ||
} | ||
this.switcher.case({ method, regexp }, handler); | ||
this.switcher.case({ method, route }, handler); | ||
} | ||
@@ -44,0 +44,0 @@ |
@@ -23,9 +23,9 @@ /** | ||
const match = condition.regexp.exec(context.request.path); | ||
if (!match) { | ||
if ((condition.method === 'ROUTED' && !context.routed) || | ||
(condition.method === 'OTHER' && context.routed)) { | ||
return false; | ||
} | ||
if ((condition.method === 'ROUTED' && !context.routed) || | ||
(condition.method === 'OTHER' && context.routed)) { | ||
const match = condition.route.exec(context.request.path); | ||
if (!match) { | ||
return false; | ||
@@ -36,4 +36,4 @@ } | ||
context.params = context.superParams || {}; | ||
context.condition = condition; | ||
const keys = condition.regexp.keys; | ||
context.matched = match[0]; | ||
const keys = condition.route.keys; | ||
let length = Object.keys(context.params).length; | ||
@@ -57,3 +57,3 @@ let i = 1; | ||
context.request = extend({}, context.request, true); | ||
context.request.path = context.request.path.replace(context.condition.regexp, ''); | ||
context.request.path = context.request.path.slice(context.matched.length); | ||
return context; | ||
@@ -60,0 +60,0 @@ } |
{ | ||
"name": "lark-router", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "An koa route initialization and configuration module.", | ||
@@ -31,3 +31,4 @@ "main": "./lib/Router.js", | ||
"path-to-regexp": "^1.5.3", | ||
"switch-case": "^0.4.0" | ||
"switch-case": "^0.4.0", | ||
"vi-misc": "^1.4.0" | ||
}, | ||
@@ -34,0 +35,0 @@ "devDependencies": { |
@@ -83,3 +83,3 @@ /** | ||
describe('route with an http server', () => { | ||
it('should response 200 for get /hello/haohao', (done) => { | ||
it('should response 200 for get /hello//haohao', (done) => { | ||
http.get('/hello/haohao') | ||
@@ -86,0 +86,0 @@ .expect(200) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
17655
13
350
1
5
+ Addedvi-misc@^1.4.0
+ Addedbluebird@3.7.2(transitive)
+ Addedvi-misc@1.14.1(transitive)