2017-11-29 15:00:50 +01:00
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
|
|
module.exports = async (ctx, next) => {
|
|
|
|
const { source } = ctx.request.query;
|
|
|
|
|
2017-11-29 16:10:13 +01:00
|
|
|
if (source && _.get(strapi.plugins, [source, 'config', 'layout', ctx.params.model, 'actions', ctx.request.route.action])) {
|
|
|
|
const [ controller, action ] = _.get(strapi.plugins, [source, 'config', 'layout', ctx.params.model, 'actions', ctx.request.route.action], []).split('.');
|
2017-11-29 15:00:50 +01:00
|
|
|
|
2017-11-29 16:10:13 +01:00
|
|
|
if (controller && action) {
|
|
|
|
// Redirect to specific controller.
|
|
|
|
return await strapi.plugins[source].controllers[controller.toLowerCase()][action](ctx);
|
|
|
|
}
|
2017-11-29 15:00:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
await next();
|
|
|
|
};
|