Skip to content

Commit

Permalink
Add TODOs about 'Controller' suffix re: balderdashy#3402 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikermcneil authored and ctartist621 committed Feb 3, 2016
1 parent 59c76b0 commit f49e38b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/app/get-route-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,33 @@ module.exports = function getRouteFor(routeQuery){
// Now look up the first route with this target (`routeTargetToLookup`).
var firstMatchingRouteAddress;
_.any(sails.router.explicitRoutes, function (routeTarget, key) {
// If route target syntax is a string, compare it directly
if ( _.isString(routeTarget) && routeTarget===routeTargetToLookup ) {
firstMatchingRouteAddress = key;
return true;
// If route target syntax is a string, compare it directly.
if ( _.isString(routeTarget) ) {
if (routeTarget===routeTargetToLookup ) {
firstMatchingRouteAddress = key;
return true;
}
else {
// TODO: If that check fails, try removing "Controller" suffix from both `routeTargetToLookup` and `routeTarget` and comparing those.
// Note that this means you _should not define `ControllerController.js`_!
}
}
else if ( _.isObject(routeTarget) ) {
// If route target syntax contains a `target` key, compare with that
if ( _.isString(routeTarget.target) && routeTarget.target===routeTargetToLookup ) {
// TODO: If that check fails, try removing "Controller" suffix from both `routeTargetToLookup` and the controller in the `routeTarget` and comparing those. // Note that this means you _should not define `ControllerController.js`_!
firstMatchingRouteAddress = key;
return true;
}
// If route target syntax contains `controller`+`action`, then check those.
else if ( _.isString(routeTarget.controller) && _.isString(routeTarget.action) && routeTarget.controller===routeTargetToLookupPieces[0] && routeTarget.action===routeTargetToLookupPieces[1] ) {
// TODO: If that check fails, try removing "Controller" suffix from both `routeTargetToLookup` and the controller in the `routeTarget` and comparing those. // Note that this means you _should not define `ControllerController.js`_!
firstMatchingRouteAddress = key;
return true;
}
// If route target syntax contains only `controller`, compare assuming the "index" action.
else if ( _.isString(routeTarget.controller) && !routeTarget.action && routeTarget.controller===routeTargetToLookupPieces[0] && 'index'===routeTargetToLookupPieces[1] ) {
// TODO: If that check fails, try removing "Controller" suffix from both `routeTargetToLookup` and the controller in the `routeTarget` and comparing those. // Note that this means you _should not define `ControllerController.js`_!
firstMatchingRouteAddress = key;
return true;
}
Expand Down

0 comments on commit f49e38b

Please sign in to comment.