diff --git a/lib/configuration/hooks/router/index.js b/lib/configuration/hooks/router/index.js index 6a9d3c26bb..30339d48df 100644 --- a/lib/configuration/hooks/router/index.js +++ b/lib/configuration/hooks/router/index.js @@ -39,6 +39,22 @@ module.exports = function (strapi) { */ initialize: function (cb) { + + // Middleware used for every routes. + // Expose the endpoint in `this`. + function globalPolicy(endpoint, value, route) { + return function * (next) { + this.request.route = { + endpoint: _.trim(endpoint), + controller: _.trim(value.controller), + action: _.trim(value.action), + splittedEndpoint: _.trim(route.endpoint), + verb: route.verb && _.trim(route.verb.toLowerCase()) + }; + yield next; + }; + } + if ((cluster.isWorker && strapi.config.reload.workers > 0) || (cluster.isMaster && strapi.config.reload.workers < 1)) { let route; let controller; @@ -52,20 +68,6 @@ module.exports = function (strapi) { }); } - // Middleware used for every routes. - // Expose the endpoint in `this`. - function globalPolicy(endpoint, route) { - return function * (next) { - this.request.route = { - endpoint: endpoint, - controller: route.controller, - firstWord: _.startsWith(route.endpoint, '/') ? route.endpoint.split('/')[1] : route.endpoint.split('/')[0], - value: route - }; - yield next; - }; - } - // Add the `dashboardPolicy` to the list of policies. if (strapi.config.dashboard.enabled) { strapi.policies.dashboardToken = dashboardTokenPolicy; @@ -89,7 +91,7 @@ module.exports = function (strapi) { policies = []; // Add the `globalPolicy`. - policies.push(globalPolicy(endpoint, route)); + policies.push(globalPolicy(endpoint, value, route)); if (_.isArray(value.policies) && !_.isEmpty(value.policies)) { _.forEach(value.policies, function (policy) {