Fix push middleware order

This commit is contained in:
Alexandre Bodin 2021-10-22 12:01:00 +02:00
parent 70ebfbbb88
commit 577e5d8997
3 changed files with 11 additions and 13 deletions

View File

@ -1,6 +1,6 @@
'use strict';
const { has, toLower, castArray, trim, prop } = require('lodash/fp');
const { has, toLower, castArray, trim, prop, isNil } = require('lodash/fp');
const compose = require('koa-compose');
const { resolveRouteMiddlewares } = require('./middleware');
@ -49,6 +49,14 @@ const createAuthenticateMiddleware = strapi => async (ctx, next) => {
return strapi.container.get('auth').authenticate(ctx, next);
};
const returnBodyMiddleware = async (ctx, next) => {
const values = await next();
if (isNil(ctx.body) && !isNil(values)) {
ctx.body = values;
}
};
module.exports = strapi => {
const authenticate = createAuthenticateMiddleware(strapi);
const authorize = createAuthorizeMiddleware(strapi);
@ -69,6 +77,7 @@ module.exports = strapi => {
authorize,
...policies,
...middlewares,
returnBodyMiddleware,
...castArray(action),
]);

View File

@ -3,8 +3,6 @@
const { propOr } = require('lodash/fp');
const policy = require('@strapi/utils/lib/policy');
const { bodyPolicy } = policy;
const getPoliciesConfig = propOr([], 'config.policies');
const resolvePolicies = route => {
@ -30,7 +28,7 @@ const resolvePolicies = route => {
await next();
};
return [policiesMiddleware, bodyPolicy];
return [policiesMiddleware];
};
module.exports = {

View File

@ -56,14 +56,6 @@ const globalPolicy = ({ method, endpoint, controller, action, plugin }) => {
};
};
const bodyPolicy = async (ctx, next) => {
const values = await next();
if (_.isNil(ctx.body) && !_.isNil(values)) {
ctx.body = values;
}
};
const get = (policy, { pluginName, apiName } = {}) => {
if (typeof policy === 'function') {
return policy;
@ -122,7 +114,6 @@ const createPolicyContext = (type, ctx) => {
module.exports = {
get,
globalPolicy,
bodyPolicy,
createPolicyFactory,
createPolicyContext,
};