datoit
Version:
An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MongoDB, MySQL, MariaDB, PostgreSQL, SQLite
26 lines (19 loc) • 718 B
JavaScript
;
const _ = require('lodash');
const compose = require('koa-compose');
const createRouteChecker = require('./routerChecker');
module.exports = strapi => {
const routerChecker = createRouteChecker(strapi);
return (value, { plugin, router }) => {
if (_.isEmpty(_.get(value, 'method')) || _.isEmpty(_.get(value, 'path'))) {
return;
}
const { method, endpoint, policies, action } = routerChecker(value, plugin);
if (_.isUndefined(action) || !_.isFunction(action)) {
return strapi.log.warn(
`Ignored attempt to bind route '${value.method} ${value.path}' to unknown controller/action.`
);
}
router[method](endpoint, compose(policies), action);
};
};