Comparing version 1.0.7 to 1.0.8
@@ -73,3 +73,3 @@ "use strict"; | ||
var exactMatch = paths.find(function (handlerPath) { | ||
return request.uri.match(handlerPath) && _this.handlers[handlerPath].verb == request.method; | ||
return request.uri.templateMatch(handlerPath) && _this.handlers[handlerPath].verb == request.method; | ||
}); | ||
@@ -79,3 +79,3 @@ var fuzzyMatch = paths.find(function (handlerPath) { | ||
? false | ||
: Uri_1.Uri.of(handlerPath).match(request.uri.path) && _this.handlers[handlerPath].verb == request.method; | ||
: handlerPath.includes("{") && Uri_1.Uri.of(handlerPath).templateMatch(request.uri.path) && _this.handlers[handlerPath].verb == request.method; | ||
}); | ||
@@ -82,0 +82,0 @@ var match = exactMatch || fuzzyMatch; |
@@ -14,3 +14,3 @@ export declare class Uri { | ||
static of(uri: string): Uri; | ||
match(path: string): boolean; | ||
templateMatch(path: string): boolean; | ||
extract(uri: string): Uri; | ||
@@ -17,0 +17,0 @@ pathParam(name: string): string; |
@@ -23,3 +23,3 @@ "use strict"; | ||
}; | ||
Uri.prototype.match = function (path) { | ||
Uri.prototype.templateMatch = function (path) { | ||
var exec = this.uriTemplateToPathParamCapturingRegex().exec(path); | ||
@@ -26,0 +26,0 @@ return exec != null; |
@@ -126,2 +126,9 @@ "use strict"; | ||
}); | ||
it("matches path params only if specified a capture in route", function () { | ||
var response = RoutingHttpHandler_1.getTo("/family", function () { | ||
return new Response_1.Response(200, new Body_1.Body("losh,bosh,tosh")); | ||
}) | ||
.match(new Request_1.Request("GET", "/family/123")); | ||
assert_1.equal(response.bodyString(), "GET to /family/123 did not match routes"); | ||
}); | ||
}); |
@@ -16,7 +16,7 @@ "use strict"; | ||
assert_1.equal(Uri_1.Uri.of("/tom/{is}/goodness") | ||
.match("/tom/is the sugar/goodness/gracious/me"), true); | ||
.templateMatch("/tom/is the sugar/goodness/gracious/me"), true); | ||
}); | ||
it("matches false when paths different", function () { | ||
assert_1.equal(Uri_1.Uri.of("/tom/{is}/goodness") | ||
.match("/tom/is/badness"), false); | ||
.templateMatch("/tom/is/badness"), false); | ||
}); | ||
@@ -23,0 +23,0 @@ it("parses out the path from uri string", function () { |
{ | ||
"name": "http4js", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "A lightweight HTTP toolkit", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
149305
989