diff --git a/generators/app/templates/app/config/route-config.js b/generators/app/templates/app/config/route-config.js index ab01309..9c736b7 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 instanceof Array) { + method.forEach(function (entry) { + registerRoute(application, controller, route, entry); + }) + } else { + registerRoute(application, controller, route, method); + } } createConfigRoute(application); @@ -66,20 +72,32 @@ 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 instanceof Array) { + var method = []; + routeItem.method.forEach(function (entry) { + 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': + return method.toLowerCase(); + break; + default: + throw 'Invalid REST "method" property in "lib/config/route.config.json": ' + method; + } +} + function registerRoute(application, controller, route, method) { application.route(route)[method](function(req, res, next) { controller[method](req, res, next);