Skip to content

Commit

Permalink
More cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikermcneil authored and ctartist621 committed Feb 3, 2016
1 parent 0bcffe0 commit 59c76b0
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/hooks/controllers/onRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ module.exports = function (sails) {
* interpretRouteSyntax
*
* "Teach" router to understand references to controllers.
* This is the event handler for the 'route:typeUnknown' emitted on `sails`.
*
* @param {Dictionary} route
* @property {String} verb
* @property {String} path
* @property {Dictionary} target
* @property {Dictionary} options
*
* @param {[type]} route [description]
* @return {[type]} [description]
* @api private
*/
return function interpretRouteSyntax (route) {
Expand All @@ -29,34 +34,35 @@ module.exports = function (sails) {
var options = route.options;


// Support various dictionary target notations, e.g.:
// `{ controller: 'UserController' }`
if (_.isObject(target) && !_.isFunction(target) && !_.isArray(target)) {

// Merge target into `options` to get hold of relevant
// route options:
options = _.merge(options, target);

// Support { controller: 'FooController' } notation
if (!_.isUndefined(target.controller)) {
if ( !_.isUndefined(target.controller) ) {
return bindController(path, target, verb, options);
}

// Support resourceful sub-mappings for verbless routes
// e.g. '/someRoute': { post: 'FooController.bar', get: '...', /* ... */ }
// If verb was manually specified in route (e.g. `get /someRoute`), ignore the sub-mappings
// If verb was manually specified in route address (e.g. `get /someRoute`), ignore the sub-mappings.
if ( !options.detectedVerb ) {
if ( target.get ) { sails.router.bind (path, target['get'],'get', options); }
if ( target.post ) { sails.router.bind (path, target['post'],'post', options); }
if ( target.put ) { sails.router.bind (path, target['put'],'put', options); }
if ( target['delete'] ) { sails.router.bind (path, target['delete'],'delete', options); }

// TODO: if there is a legitimate use case for it, add other HTTP verbs here for completeness.
}

// Lone action syntax, e.g.:
// '/someRoute': { action: 'find', model: 'foo' }
//
// (useful for explicitly routing a URL to a blueprint action)
if ( !_.isUndefined(target.action) ) {
else if ( !_.isUndefined(target.action) ) {

// Merge target def. into route options:
options.action = target.action;
Expand All @@ -66,7 +72,7 @@ module.exports = function (sails) {
}

// Support string ('FooController.bar') notation
if (_.isString(target)) {
else if (_.isString(target)) {

// Handle dot notation
var parsedTarget = target.match(/^([^.]+)\.?([^.]*)?$/);
Expand Down

0 comments on commit 59c76b0

Please sign in to comment.