Comparing version 1.0.0-alpha-04 to 1.0.0-alpha-05
@@ -96,4 +96,3 @@ 'use strict'; | ||
getPattern(url) { | ||
return url.split('/').filter(item => !!item).map(item => { | ||
return url.split(/\/([^\/]+)\//g).filter(item => !!item).map(item => { | ||
// pattern definition | ||
@@ -147,3 +146,3 @@ let obj = { | ||
} | ||
let pattern = new RegExp(source); | ||
let pattern = new RegExp('^' + source + '$'); | ||
let start = index; | ||
@@ -175,3 +174,3 @@ let end = start + replace.length; | ||
let source = '([\\s\\S]+)'; | ||
let pattern = new RegExp(source); | ||
let pattern = new RegExp('^' + source + '$'); | ||
obj.patterns.push({ | ||
@@ -219,3 +218,3 @@ source, | ||
// pattern | ||
obj.pattern = new RegExp(obj.source); | ||
obj.pattern = new RegExp('^' + obj.source + '$'); | ||
@@ -237,5 +236,10 @@ return obj; | ||
parseRequest(pathname, method) { | ||
let url = pathname.split('/').filter(item => !!item); | ||
if (this.pattern.length !== url.length || this.methods.indexOf(method) === -1) { | ||
let url = pathname.split(/\/([^\/]+)\//g).filter(item => !!item); | ||
let pl = this.pattern.length; | ||
if (this.methods.indexOf(method) === -1) { | ||
return false; | ||
} else if (url.length > pl) { | ||
let last = url.splice(pl, url.length - 1); | ||
last.unshift(url.pop()); | ||
url.push(last.join('/')); | ||
} | ||
@@ -247,3 +251,3 @@ let query = new Map(); | ||
if (result) { | ||
result.forEach((k, v) => query.set(k, v)); | ||
result.forEach((v, k) => query.set(k, v)); | ||
return Type.isObject(result); | ||
@@ -302,4 +306,3 @@ } | ||
let url = matches.join('/'); | ||
let url = ('/' + matches.join('/')).replace(/\/\//g, '/'); | ||
if (paramsMap.size > 0) { | ||
@@ -311,4 +314,3 @@ url += '?'; | ||
} | ||
return '/' + url; | ||
return url; | ||
} | ||
@@ -315,0 +317,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"description": "Lightweight application framework with dyependency injection and dynamic type checking for node js", | ||
"version": "1.0.0-alpha-04", | ||
"version": "1.0.0-alpha-05", | ||
"dependencies": { | ||
@@ -8,0 +8,0 @@ "di-node": "0.2.x", |
88060
2938