Comparing version 1.0.2 to 1.0.3
@@ -5,3 +5,3 @@ var http = require("http"); | ||
//parameters are between {curlybraces} | ||
var routes = ["GET /", "GET /dogs/{dog}", "GET /cats/{cat}", "GET /boing"]; | ||
var routes = ["GET /", "GET /dogs/{dog}", "GET /cats/{cat}", "GET /boing", "GET /n/{n}/m/{m}"]; | ||
@@ -17,3 +17,2 @@ //overalls is configured with an array or object with paths | ||
res.writeHead(200, {"Content-Type": "text/plain"}); | ||
if(req.params) { | ||
@@ -25,3 +24,6 @@ | ||
res.write("cat: " + req.params.cat); | ||
} | ||
} else if (req.params.n || req.params.m) { | ||
res.write("n: " + req.params.n + " m: " + req.params.m); | ||
console.log(req.params); | ||
}; | ||
@@ -28,0 +30,0 @@ } else { |
@@ -58,26 +58,29 @@ function splitPath (path) { | ||
if (req.hasOwnProperty("params")) { | ||
if (req.hasOwnProperty("params")) { | ||
return; | ||
} | ||
var i, match, il = requestSegments.length; | ||
} | ||
if(requestSegments.length !== routeSegments.length) { | ||
return; | ||
} | ||
for (i = 0; i < il; i += 1) { | ||
match = compareSegments(routeSegments[i], requestSegments[i]); | ||
var i, match, il = requestSegments.length; | ||
if (typeof match === "object") { | ||
req.params = {}; | ||
req.params[match.key] = match.value; | ||
} else if (!match) { | ||
delete req.params | ||
return; | ||
} | ||
if(requestSegments.length !== routeSegments.length) { | ||
return; | ||
} | ||
if ((i === (il-1)) && match) { | ||
req.match = routeSegments.join("/"); | ||
} | ||
for (i = 0; i < il; i += 1) { | ||
match = compareSegments(routeSegments[i], requestSegments[i]); | ||
if (typeof match === "object") { | ||
req.params = req.params || {}; | ||
req.params[match.key] = match.value; | ||
} else if (!match) { | ||
delete req.params | ||
return; | ||
} | ||
if ((i === (il-1)) && match) { | ||
req.match = routeSegments.join("/"); | ||
} | ||
} | ||
}); | ||
@@ -84,0 +87,0 @@ }; |
{ | ||
"name": "overalls", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Decorate HTTP requests with path parameters", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
13923
253