mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 23:24:03 +00:00
Fix push middleware order
This commit is contained in:
parent
70ebfbbb88
commit
577e5d8997
@ -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),
|
||||
]);
|
||||
|
||||
|
||||
@ -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 = {
|
||||
|
||||
@ -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,
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user