2018-12-06 18:03:56 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const path = require('path');
|
2019-06-08 18:50:07 +02:00
|
|
|
const koaStatic = require('koa-static');
|
2021-10-14 10:48:29 -04:00
|
|
|
const session = require('koa-session');
|
|
|
|
const swaggerUi = require('swagger-ui-dist');
|
2018-12-06 18:03:56 +01:00
|
|
|
|
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 }) => {
|
2021-10-14 10:48:29 -04:00
|
|
|
const sessionConfig = strapi.config.get('plugin.documentation').session;
|
|
|
|
strapi.server.app.keys = sessionConfig.secretKeys;
|
|
|
|
strapi.server.app.use(session(sessionConfig, strapi.server.app));
|
2021-10-05 11:39:02 -04:00
|
|
|
|
|
|
|
strapi.server.routes([
|
|
|
|
{
|
|
|
|
method: 'GET',
|
|
|
|
path: '/plugins/documentation/(.*)',
|
|
|
|
async handler(ctx, next) {
|
|
|
|
ctx.url = path.basename(ctx.url);
|
|
|
|
|
|
|
|
return koaStatic(swaggerUi.getAbsoluteFSPath(), {
|
2021-10-14 10:48:29 -04:00
|
|
|
maxage: sessionConfig.cookie.maxAge,
|
2021-10-05 11:39:02 -04:00
|
|
|
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
|
|
|
};
|