mirror of
https://github.com/strapi/strapi.git
synced 2025-12-25 14:14:10 +00:00
Migrate middlwares to programmatic for plugin that do not need to export them
This commit is contained in:
parent
43c7e47f2b
commit
c7a94ed081
@ -14,6 +14,7 @@
|
||||
"dependencies": {
|
||||
"@strapi/admin": "3.6.8",
|
||||
"@strapi/plugin-documentation": "3.6.8",
|
||||
"@strapi/plugin-sentry": "3.6.8",
|
||||
"@strapi/plugin-graphql": "3.6.8",
|
||||
"@strapi/plugin-i18n": "3.6.8",
|
||||
"@strapi/plugin-users-permissions": "3.6.8",
|
||||
|
||||
@ -10,6 +10,9 @@ const DELETE_FILE_MUTATION_NAME = 'removeFile';
|
||||
|
||||
const FILE_INFO_INPUT_TYPE_NAME = 'FileInfoInput';
|
||||
|
||||
/**
|
||||
* @param {{ strapi: import('@strapi/strapi').Strapi }}
|
||||
*/
|
||||
module.exports = ({ strapi }) => {
|
||||
const { service: getGraphQLService, config: graphQLConfig } = strapi.plugin('graphql');
|
||||
const { service: getUploadService } = strapi.plugin('upload');
|
||||
|
||||
@ -4,11 +4,16 @@ const { resolve } = require('path');
|
||||
const range = require('koa-range');
|
||||
const koaStatic = require('koa-static');
|
||||
|
||||
module.exports = () => {
|
||||
/**
|
||||
* Programmatic upload middleware. We do not want to export it
|
||||
* @param {{ strapi: import('@strapi/strapi').Strapi }}
|
||||
*/
|
||||
module.exports = ({ strapi }) => {
|
||||
const configPublicPath = strapi.config.get(
|
||||
'middleware.settings.public.path',
|
||||
strapi.config.paths.static
|
||||
);
|
||||
|
||||
const staticDir = resolve(strapi.dirs.root, configPublicPath);
|
||||
|
||||
strapi.server.app.on('error', err => {
|
||||
@ -1,9 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const registerUploadMiddlware = require('./controllers/upload-middleware');
|
||||
const registerUploadMiddlware = require('./middlewares/upload');
|
||||
|
||||
/**
|
||||
* Register upload plugin
|
||||
* @param {{ strapi: import('@strapi/strapi').Strapi }}
|
||||
*/
|
||||
module.exports = async ({ strapi }) => {
|
||||
await registerUploadMiddlware();
|
||||
await registerUploadMiddlware({ strapi });
|
||||
|
||||
if (strapi.plugin('graphql')) {
|
||||
require('./graphql')({ strapi });
|
||||
|
||||
@ -6,6 +6,7 @@ const koaStatic = require('koa-static');
|
||||
|
||||
const initialRoutes = [];
|
||||
|
||||
// TODO: delete when refactoring documentation plugin for v4
|
||||
module.exports = {
|
||||
defaults: { documentation: { enabled: true } },
|
||||
load: {
|
||||
|
||||
13
packages/plugins/sentry/server/index.js
Normal file
13
packages/plugins/sentry/server/index.js
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const register = require('./register');
|
||||
const bootstrap = require('./bootstrap');
|
||||
const services = require('./services');
|
||||
const config = require('./config');
|
||||
|
||||
module.exports = () => ({
|
||||
register,
|
||||
bootstrap,
|
||||
config,
|
||||
services,
|
||||
});
|
||||
@ -1,7 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const sentry = require('./sentry');
|
||||
|
||||
module.exports = {
|
||||
sentry,
|
||||
};
|
||||
34
packages/plugins/sentry/server/middlewares/sentry.js
Normal file
34
packages/plugins/sentry/server/middlewares/sentry.js
Normal file
@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Programmatic upload middleware. We do not want to export it
|
||||
* @param {{ strapi: import('@strapi/strapi').Strapi }}
|
||||
*/
|
||||
module.exports = ({ strapi }) => {
|
||||
const sentry = strapi.plugin('sentry').service('sentry');
|
||||
sentry.init();
|
||||
|
||||
strapi.server.use(async (ctx, next) => {
|
||||
try {
|
||||
await next();
|
||||
} catch (error) {
|
||||
sentry.sendError(error, (scope, sentryInstance) => {
|
||||
scope.addEventProcessor(event => {
|
||||
// Parse Koa context to add error metadata
|
||||
return sentryInstance.Handlers.parseRequest(event, ctx.request, {
|
||||
// Don't parse the transaction name, we'll do it manually
|
||||
transaction: false,
|
||||
});
|
||||
});
|
||||
|
||||
// Manually add transaction name
|
||||
scope.setTag('transaction', `${ctx.method} ${ctx.request.url}`);
|
||||
// Manually add Strapi version
|
||||
scope.setTag('strapi_version', strapi.config.info.strapi);
|
||||
scope.setTag('method', ctx.method);
|
||||
});
|
||||
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -1,36 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
defaults: { sentry: { enabled: true } },
|
||||
load: {
|
||||
beforeInitialize() {
|
||||
strapi.config.middleware.load.after.unshift('sentry');
|
||||
},
|
||||
initialize() {
|
||||
const sentry = strapi.plugin('sentry').service('sentry');
|
||||
sentry.init();
|
||||
|
||||
strapi.server.use(async (ctx, next) => {
|
||||
try {
|
||||
await next();
|
||||
} catch (error) {
|
||||
sentry.sendError(error, (scope, sentryInstance) => {
|
||||
scope.addEventProcessor(event => {
|
||||
// Parse Koa context to add error metadata
|
||||
return sentryInstance.Handlers.parseRequest(event, ctx.request, {
|
||||
// Don't parse the transaction name, we'll do it manually
|
||||
transaction: false,
|
||||
});
|
||||
});
|
||||
// Manually add transaction name
|
||||
scope.setTag('transaction', `${ctx.method} ${ctx.request.url}`);
|
||||
// Manually add Strapi version
|
||||
scope.setTag('strapi_version', strapi.config.info.strapi);
|
||||
scope.setTag('method', ctx.method);
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
11
packages/plugins/sentry/server/register.js
Normal file
11
packages/plugins/sentry/server/register.js
Normal file
@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const registerSentryMiddleware = require('./middlewares/sentry');
|
||||
|
||||
/**
|
||||
* Register sentry plugin
|
||||
* @param {{ strapi: import('@strapi/strapi').Strapi }}
|
||||
*/
|
||||
module.exports = ({ strapi }) => {
|
||||
registerSentryMiddleware({ strapi });
|
||||
};
|
||||
@ -1,13 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
const bootstrap = require('./server/bootstrap');
|
||||
const services = require('./server/services');
|
||||
const middlewares = require('./server/middlewares');
|
||||
const config = require('./server/config');
|
||||
|
||||
module.exports = () => ({
|
||||
bootstrap,
|
||||
config,
|
||||
middlewares,
|
||||
services,
|
||||
});
|
||||
module.exports = require('./server');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user