mirror of
https://github.com/strapi/strapi.git
synced 2025-08-09 01:07:27 +00:00
Fix retours PR
This commit is contained in:
parent
5b575ffac5
commit
b58d11d18a
@ -277,17 +277,13 @@ const enableHookNestedDependencies = function (name, flattenHooksConfig) {
|
||||
if (isEmpty(get(flattenHooksConfig, name, true))) {
|
||||
|
||||
// Check if database connector is used
|
||||
let isUsed = false;
|
||||
forEach(get(strapi, 'api', {}), api => {
|
||||
if (!api.models) return;
|
||||
|
||||
forEach(api.models, model => {
|
||||
if (get(strapi.connection, model.connection, {}).connector === name) isUsed = true;
|
||||
});
|
||||
});
|
||||
const modelUsed = Object.keys(this.api || {})
|
||||
.filter(x => isObject(this.api[x].models)) // Filter API with models
|
||||
.map(x => this.api[x].models) // Keep models
|
||||
.filter(model => get(this.connection, model.connection, {}).connector === name) || 0; // Filter model with the right connector
|
||||
|
||||
flattenHooksConfig[name] = {
|
||||
enabled: isUsed
|
||||
enabled: modelUsed.length > 0 // Will return false if there is no model, else true.
|
||||
};
|
||||
|
||||
// Enabled dependencies.
|
||||
|
@ -47,7 +47,7 @@ module.exports = strapi => {
|
||||
initialize: function(cb) {
|
||||
strapi.app.use(
|
||||
async (ctx, next) => {
|
||||
if (ctx.admin) return next();
|
||||
if (ctx.request.admin) return next();
|
||||
|
||||
await strapi.koaMiddlewares.kcors({
|
||||
origin: strapi.config.middleware.settings.cors.origin,
|
||||
|
@ -27,7 +27,7 @@ module.exports = strapi => {
|
||||
initialize: function(cb) {
|
||||
strapi.app.use(
|
||||
async (ctx, next) => {
|
||||
if (ctx.admin) return next();
|
||||
if (ctx.request.admin) return next();
|
||||
|
||||
strapi.koaMiddlewares.convert(
|
||||
strapi.koaMiddlewares.lusca.csp(strapi.config.middleware.settings.csp)
|
||||
|
@ -29,7 +29,7 @@ module.exports = strapi => {
|
||||
initialize: function(cb) {
|
||||
strapi.app.use(
|
||||
async (ctx, next) => {
|
||||
if (ctx.admin) return next();
|
||||
if (ctx.request.admin) return next();
|
||||
|
||||
await strapi.koaMiddlewares.convert(
|
||||
strapi.koaMiddlewares.lusca.csrf({
|
||||
|
@ -29,7 +29,7 @@ module.exports = strapi => {
|
||||
initialize: function(cb) {
|
||||
strapi.app.use(
|
||||
async (ctx, next) => {
|
||||
if (ctx.admin) return next();
|
||||
if (ctx.request.admin) return next();
|
||||
|
||||
strapi.koaMiddlewares.convert(
|
||||
strapi.koaMiddlewares.lusca.hsts({
|
||||
|
@ -3,17 +3,19 @@
|
||||
const glob = require('glob');
|
||||
const path = require('path');
|
||||
const { parallel } = require('async');
|
||||
const { after, includes, indexOf, drop, dropRight, uniq, defaultsDeep, get, set, isEmpty, isUndefined, union, keys } = require('lodash');
|
||||
const { after, includes, indexOf, drop, dropRight, uniq, defaultsDeep, get, set, isEmpty, isUndefined, union } = require('lodash');
|
||||
|
||||
module.exports = function() {
|
||||
// Set if is admin destination for middleware application.
|
||||
// TODO: Use dynamic config for admin url.
|
||||
strapi.app.use(async (ctx, next) => {
|
||||
const accepted = keys(strapi.plugins).map(url => `^\/${url}`);
|
||||
accepted.push('^\/admin');
|
||||
const isMatch = accepted.some(rx => new RegExp(rx).test(ctx.request.url));
|
||||
set(ctx, 'admin', isMatch);
|
||||
return next();
|
||||
const accepted = Object.keys(strapi.plugins).map(url => `^\/${url}`).concat(['^\/admin']);
|
||||
|
||||
strapi.app.use(async (ctx, next) => {
|
||||
ctx.request.admin = accepted.some(rx => new RegExp(rx).test(ctx.request.url));
|
||||
|
||||
return next();
|
||||
});
|
||||
});
|
||||
|
||||
// Method to initialize middlewares and emit an event.
|
||||
|
@ -28,7 +28,7 @@ module.exports = strapi => {
|
||||
initialize: function(cb) {
|
||||
strapi.app.use(
|
||||
async (ctx, next) => {
|
||||
if (ctx.admin) return next();
|
||||
if (ctx.request.admin) return next();
|
||||
|
||||
strapi.koaMiddlewares.convert(
|
||||
strapi.koaMiddlewares.lusca.p3p({
|
||||
|
@ -28,7 +28,7 @@ module.exports = strapi => {
|
||||
initialize: function(cb) {
|
||||
strapi.app.use(
|
||||
async (ctx, next) => {
|
||||
if (ctx.admin) return next();
|
||||
if (ctx.request.admin) return next();
|
||||
|
||||
strapi.koaMiddlewares.convert(
|
||||
strapi.koaMiddlewares.lusca.xframe({
|
||||
|
@ -28,7 +28,7 @@ module.exports = strapi => {
|
||||
initialize: function(cb) {
|
||||
strapi.app.use(
|
||||
async (ctx, next) => {
|
||||
if (ctx.admin) return next();
|
||||
if (ctx.request.admin) return next();
|
||||
|
||||
strapi.koaMiddlewares.convert(
|
||||
strapi.koaMiddlewares.lusca.xssProtection({
|
||||
|
Loading…
x
Reference in New Issue
Block a user