From d4004876012fce4d69d5d84a17ad819436803f2b Mon Sep 17 00:00:00 2001 From: heiko87 Date: Thu, 3 Sep 2015 09:12:37 +0200 Subject: [PATCH 1/2] methods as array in route.config.json possible Now it's possible to have objects in the route.config.json containing the method's as an array. E.g.: { "route": "/v1/user", "method": [ "GET", "POST" ], "controller": "../controllers/v1/user/user-controller" } --- .../app/templates/app/config/route-config.js | 51 ++++++++++++++----- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/generators/app/templates/app/config/route-config.js b/generators/app/templates/app/config/route-config.js index ab01309..9baa89c 100644 --- a/generators/app/templates/app/config/route-config.js +++ b/generators/app/templates/app/config/route-config.js @@ -13,7 +13,13 @@ function registerRoutes(application) { var route = getRoute(routeItem); var method = getMethod(routeItem); - registerRoute(application, controller, route, method); + if (method.constructor === Array) { + method.forEach(function (entry) { + registerRoute(application, controller, route, entry); + }) + } else { + registerRoute(application, controller, route, method); + } } createConfigRoute(application); @@ -66,17 +72,38 @@ function getMethod(routeItem) { throw 'Undefined or empty "method" property in "lib/config/route.config.json"'; } - var method = routeItem.method.toLowerCase(); - - switch(method) { - case 'get': - case 'put': - case 'post': - case 'delete': - return method; - break; - default: - throw 'Invalid REST "method" property in "lib/config/route.config.json": ' + method; + var method; + + if (routeItem.method.constructor === Array) { + method = []; + routeItem.method.forEach(function (entry) { + switch (entry.toLowerCase()) { + case 'get': + case 'put': + case 'post': + case 'delete': + method.push(entry.toLowerCase()); + break; + default: + throw 'Invalid REST "method" property in "lib/config/route.config.json": ' + method; + } + + }); + + return method; + } else { + method = routeItem.method.toLowerCase(); + + switch (method) { + case 'get': + case 'put': + case 'post': + case 'delete': + return method; + break; + default: + throw 'Invalid REST "method" property in "lib/config/route.config.json": ' + method; + } } } From 76465a5f19c62d241fd8c97a83117eaf1133388a Mon Sep 17 00:00:00 2001 From: heiko87 Date: Thu, 29 Oct 2015 09:24:20 +0100 Subject: [PATCH 2/2] updated route-config.js --- .../app/templates/app/config/route-config.js | 41 ++++++++----------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/generators/app/templates/app/config/route-config.js b/generators/app/templates/app/config/route-config.js index 9baa89c..9c736b7 100644 --- a/generators/app/templates/app/config/route-config.js +++ b/generators/app/templates/app/config/route-config.js @@ -13,7 +13,7 @@ function registerRoutes(application) { var route = getRoute(routeItem); var method = getMethod(routeItem); - if (method.constructor === Array) { + if (method instanceof Array) { method.forEach(function (entry) { registerRoute(application, controller, route, entry); }) @@ -74,37 +74,28 @@ function getMethod(routeItem) { var method; - if (routeItem.method.constructor === Array) { - method = []; + if (routeItem.method instanceof Array) { + var method = []; routeItem.method.forEach(function (entry) { - switch (entry.toLowerCase()) { + method.push(validateMethod(entry.toLowerCase())); + }); + return method; + } else { + return validateMethod(routeItem.method.toLowerCase()); + } +} + +function validateMethod(method) { + switch (method.toLowerCase()) { case 'get': case 'put': case 'post': case 'delete': - method.push(entry.toLowerCase()); - break; + return method.toLowerCase(); + break; default: - throw 'Invalid REST "method" property in "lib/config/route.config.json": ' + method; - } - - }); - - return method; - } else { - method = routeItem.method.toLowerCase(); - - switch (method) { - case 'get': - case 'put': - case 'post': - case 'delete': - return method; - break; - default: - throw 'Invalid REST "method" property in "lib/config/route.config.json": ' + method; + throw 'Invalid REST "method" property in "lib/config/route.config.json": ' + method; } - } } function registerRoute(application, controller, route, method) {