2018-12-06 18:03:56 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const path = require('path');
|
2020-10-27 11:27:17 +01:00
|
|
|
const _ = require('lodash');
|
2019-06-08 18:50:07 +02:00
|
|
|
const koaStatic = require('koa-static');
|
2018-12-06 18:03:56 +01:00
|
|
|
|
|
|
|
const initialRoutes = [];
|
|
|
|
|
2021-09-29 10:47:10 +02:00
|
|
|
// TODO: delete when refactoring documentation plugin for v4
|
2021-10-05 11:39:02 -04:00
|
|
|
module.exports = async ({ strapi }) => {
|
|
|
|
// strapi.config.middleware.load.before.push('documentation');
|
|
|
|
|
|
|
|
initialRoutes.push(..._.cloneDeep(strapi.plugins.documentation.routes));
|
|
|
|
|
|
|
|
const swaggerUi = require('swagger-ui-dist');
|
|
|
|
|
|
|
|
// Find the plugins routes.
|
|
|
|
strapi.plugins.documentation.routes = strapi.plugins.documentation.routes.map((route, index) => {
|
|
|
|
if (route.handler === 'Documentation.getInfos') {
|
|
|
|
return route;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (route.handler === 'Documentation.index' || route.path === '/login') {
|
|
|
|
route.config.policies = initialRoutes[index].config.policies;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set prefix to empty to be able to customise it.
|
|
|
|
if (strapi.config.has('plugins.documentation.x-strapi-config.path')) {
|
|
|
|
route.config.prefix = '';
|
|
|
|
route.path = `/${strapi.config.get('plugin.documentation.x-strapi-config').path}${
|
|
|
|
route.path
|
|
|
|
}`.replace('//', '/');
|
|
|
|
}
|
|
|
|
|
|
|
|
return route;
|
|
|
|
});
|
|
|
|
|
|
|
|
strapi.server.routes([
|
|
|
|
{
|
|
|
|
method: 'GET',
|
|
|
|
path: '/plugins/documentation/(.*)',
|
|
|
|
async handler(ctx, next) {
|
|
|
|
ctx.url = path.basename(ctx.url);
|
|
|
|
|
|
|
|
return koaStatic(swaggerUi.getAbsoluteFSPath(), {
|
|
|
|
maxage: 6000,
|
|
|
|
defer: true,
|
|
|
|
})(ctx, next);
|
|
|
|
},
|
|
|
|
config: {
|
|
|
|
auth: false,
|
|
|
|
},
|
2019-06-08 18:50:07 +02:00
|
|
|
},
|
2021-10-05 11:39:02 -04:00
|
|
|
]);
|
2019-04-15 18:57:58 +02:00
|
|
|
};
|