Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added comments

  • Loading branch information...
commit dd1e201eb1d6484ae7abb43c9889317b739bc147 1 parent 2b7202c
Jason Rudland authored
Showing with 7 additions and 3 deletions.
  1. +7 −3 lib/rapid-rest.js
10 lib/rapid-rest.js
View
@@ -63,9 +63,9 @@ module.exports = function() {
}
});
req.on('end', function () {
- //TODO: Switch contentType
+ //TODO: Switch contentType or pass parser as a parameter
- var data = body;// JSON.parse(body);
+ var data = JSON.parse(body);
fn(req, res, segments, data);
});
}
@@ -101,17 +101,21 @@ module.exports = function() {
var urlDef;
var urlPath = req.url;
+
+ //Optimization for URLs that have no query string
if(req.url.indexOf("?")){
urlDef = url.parse(req.url,true);
urlPath = urlDef.pathname;
+ req.query = urlDef.query;
}
+ // Check for matching pattern
for (var pattern in rest.matchDefs) {
var matchDef = rest.matchDefs[pattern];
var urlParams = urlPath.match(matchDef.re);
if ( urlParams !== null){
- // Validate required querystring parameters
+ // Validate required querystring kvps
if(urlDef && matchDef.queryKeys){
for(var kvp in urlDef.query) {
if(!matchDef.query[kvp]){
Please sign in to comment.
Something went wrong with that request. Please try again.