mirror of
https://github.com/strapi/strapi.git
synced 2025-12-25 22:23:10 +00:00
Use default config middleware and load plugins middlewares
This commit is contained in:
parent
6d253cef87
commit
a2c8e212fc
5
packages/strapi-middleware-views/lib/defaults.js
Normal file
5
packages/strapi-middleware-views/lib/defaults.js
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"views": {
|
||||
"enabled": false
|
||||
}
|
||||
}
|
||||
@ -18,16 +18,6 @@ const views = require('koa-views');
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
views: {
|
||||
enabled: false
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
{
|
||||
"users-permissions": {
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
initialize: function(cb) {
|
||||
strapi.app.use(async (ctx, next) => {
|
||||
await next();
|
||||
});
|
||||
|
||||
cb();
|
||||
}
|
||||
};
|
||||
};
|
||||
@ -26,7 +26,8 @@
|
||||
"dependencies": {
|
||||
"bcryptjs": "^2.4.3",
|
||||
"jsonwebtoken": "^8.1.0",
|
||||
"sendmail": "^1.2.0"
|
||||
"sendmail": "^1.2.0",
|
||||
"strapi-helper-plugin": "3.0.0-alpha.6.7"
|
||||
},
|
||||
"author": {
|
||||
"name": "A Strapi developer",
|
||||
@ -44,5 +45,21 @@
|
||||
"node": ">= 7.0.0",
|
||||
"npm": ">= 3.0.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"cross-env": "^5.1.1",
|
||||
"eslint": "^4.11.0",
|
||||
"eslint-config-airbnb": "^15.1.0",
|
||||
"eslint-config-airbnb-base": "^11.3.2",
|
||||
"eslint-config-prettier": "^2.8.0",
|
||||
"eslint-import-resolver-webpack": "^0.8.3",
|
||||
"eslint-plugin-import": "^2.8.0",
|
||||
"eslint-plugin-jsx-a11y": "^6.0.2",
|
||||
"eslint-plugin-react": "^7.5.1",
|
||||
"eslint-plugin-redux-saga": "^0.4.0",
|
||||
"plop": "^1.9.0",
|
||||
"prettier": "^1.8.2",
|
||||
"rimraf": "^2.6.2",
|
||||
"webpack": "^3.8.1"
|
||||
}
|
||||
}
|
||||
@ -174,7 +174,7 @@ module.exports.app = async function() {
|
||||
// Preset config in alphabetical order.
|
||||
this.config.middleware.settings = Object.keys(this.middleware).reduce((acc, current) => {
|
||||
// Try to find the settings in the current environment, then in the main configurations.
|
||||
const currentSettings = flattenMiddlewaresConfig[current] || this.config[current];
|
||||
const currentSettings = merge(get(this.middleware[current], ['defaults', current], {}), flattenMiddlewaresConfig[current] || this.config[current]);
|
||||
acc[current] = !isObject(currentSettings) ? {} : currentSettings;
|
||||
|
||||
if (!acc[current].hasOwnProperty('enabled')) {
|
||||
|
||||
@ -5,7 +5,7 @@ const glob = require('glob');
|
||||
const path = require('path');
|
||||
const utils = require('../utils');
|
||||
const { parallel } = require('async');
|
||||
const { upperFirst, lowerFirst } = require('lodash');
|
||||
const { upperFirst, lowerFirst, endsWith } = require('lodash');
|
||||
|
||||
module.exports = function() {
|
||||
this.middleware = {};
|
||||
@ -50,7 +50,7 @@ module.exports = function() {
|
||||
const cwd = this.config.appPath;
|
||||
|
||||
glob(
|
||||
'./node_modules/*(strapi-middleware-*)',
|
||||
'./node_modules/*(strapi-middleware-*)/*/*(index|defaults).*(js|json)',
|
||||
{
|
||||
cwd
|
||||
},
|
||||
@ -67,7 +67,7 @@ module.exports = function() {
|
||||
const cwd = path.resolve(__dirname, '..', 'middlewares');
|
||||
|
||||
glob(
|
||||
'./!(index.js)',
|
||||
'./*/*(index|defaults).*(js|json)',
|
||||
{
|
||||
cwd
|
||||
},
|
||||
@ -84,7 +84,24 @@ module.exports = function() {
|
||||
const cwd = path.resolve(this.config.appPath, 'middlewares');
|
||||
|
||||
glob(
|
||||
'./*',
|
||||
'./*/*(index|defaults).*(js|json)',
|
||||
{
|
||||
cwd
|
||||
},
|
||||
(err, files) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
mountMiddlewares.call(this, files, cwd)(resolve, reject);
|
||||
}
|
||||
);
|
||||
}),
|
||||
new Promise((resolve, reject) => {
|
||||
const cwd = path.resolve(this.config.appPath, 'plugins');
|
||||
|
||||
glob(
|
||||
'./**/middlewares/*/*(index|defaults).*(js|json)',
|
||||
{
|
||||
cwd
|
||||
},
|
||||
@ -144,16 +161,20 @@ const mountMiddlewares = function (files, cwd) {
|
||||
const name = p.replace(/^.\/node_modules\/strapi-middleware-/, './')
|
||||
.split('/')[1];
|
||||
|
||||
this.middleware[name] = {
|
||||
this.middleware[name] = this.middleware[name] || {
|
||||
loaded: false
|
||||
};
|
||||
|
||||
// Lazy loading.
|
||||
Object.defineProperty(this.middleware[name], 'load', {
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
get: () => require(path.resolve(cwd, p))(this)
|
||||
});
|
||||
if (endsWith(p, 'index.js')) {
|
||||
// Lazy loading.
|
||||
Object.defineProperty(this.middleware[name], 'load', {
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
get: () => require(path.resolve(cwd, p))(this)
|
||||
});
|
||||
} else if (endsWith(p, 'defaults.json')) {
|
||||
this.middleware[name].defaults = require(path.resolve(cwd, p));
|
||||
}
|
||||
|
||||
cb();
|
||||
}),
|
||||
|
||||
5
packages/strapi/lib/middlewares/boom/defaults.json
Normal file
5
packages/strapi/lib/middlewares/boom/defaults.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"boom": {
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
@ -11,16 +11,6 @@ const delegate = require('delegates');
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
boom: {
|
||||
enabled: true
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
25
packages/strapi/lib/middlewares/cors/defaults.json
Normal file
25
packages/strapi/lib/middlewares/cors/defaults.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"cors": {
|
||||
"enabled": false,
|
||||
"origin": true,
|
||||
"expose": [
|
||||
"WWW-Authenticate",
|
||||
"Server-Authorization"
|
||||
],
|
||||
"maxAge": 31536000,
|
||||
"credentials": true,
|
||||
"methods": [
|
||||
"GET",
|
||||
"POST",
|
||||
"PUT",
|
||||
"PATCH",
|
||||
"DELETE",
|
||||
"HEAD"
|
||||
],
|
||||
"headers": [
|
||||
"Content-Type",
|
||||
"Authorization"
|
||||
],
|
||||
"keepHeadersOnError": false
|
||||
}
|
||||
}
|
||||
@ -10,36 +10,6 @@
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
cors: {
|
||||
enabled: false,
|
||||
origin: true,
|
||||
expose: [
|
||||
'WWW-Authenticate',
|
||||
'Server-Authorization'
|
||||
],
|
||||
maxAge: 31536000,
|
||||
credentials: true,
|
||||
methods: [
|
||||
'GET',
|
||||
'POST',
|
||||
'PUT',
|
||||
'PATCH',
|
||||
'DELETE',
|
||||
'HEAD'
|
||||
],
|
||||
headers: [
|
||||
'Content-Type',
|
||||
'Authorization'
|
||||
],
|
||||
keepHeadersOnError: false
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
5
packages/strapi/lib/middlewares/cron/defaults.json
Normal file
5
packages/strapi/lib/middlewares/cron/defaults.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"cron": {
|
||||
"enabled": false
|
||||
}
|
||||
}
|
||||
@ -14,16 +14,6 @@ const cron = require('node-schedule');
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
cron: {
|
||||
enabled: false
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
5
packages/strapi/lib/middlewares/csp/defaults.json
Normal file
5
packages/strapi/lib/middlewares/csp/defaults.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"csp": {
|
||||
"enabled": false
|
||||
}
|
||||
}
|
||||
@ -10,16 +10,6 @@
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
csp: {
|
||||
enabled: false
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
7
packages/strapi/lib/middlewares/csrf/defaults.json
Normal file
7
packages/strapi/lib/middlewares/csrf/defaults.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"csrf": {
|
||||
"enabled": false,
|
||||
"key": "_csrf",
|
||||
"secret": "_csrfSecret"
|
||||
}
|
||||
}
|
||||
@ -10,18 +10,6 @@
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
csrf: {
|
||||
enabled: false,
|
||||
key: '_csrf',
|
||||
secret: '_csrfSecret'
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
6
packages/strapi/lib/middlewares/favicon/defaults.json
Normal file
6
packages/strapi/lib/middlewares/favicon/defaults.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"favicon": {
|
||||
"path": "favicon.ico",
|
||||
"maxAge": 86400000
|
||||
}
|
||||
}
|
||||
@ -13,17 +13,6 @@ const path = require('path');
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
favicon: {
|
||||
path: 'favicon.ico',
|
||||
maxAge: 86400000
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
5
packages/strapi/lib/middlewares/gzip/defaults.json
Normal file
5
packages/strapi/lib/middlewares/gzip/defaults.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"gzip": {
|
||||
"enabled": false
|
||||
}
|
||||
}
|
||||
@ -6,16 +6,6 @@
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
gzip: {
|
||||
enabled: false
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
7
packages/strapi/lib/middlewares/hsts/defaults.json
Normal file
7
packages/strapi/lib/middlewares/hsts/defaults.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"hsts": {
|
||||
"enabled": true,
|
||||
"maxAge": 31536000,
|
||||
"includeSubDomains": true
|
||||
}
|
||||
}
|
||||
@ -10,18 +10,6 @@
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
hsts: {
|
||||
enabled: true,
|
||||
maxAge: 31536000,
|
||||
includeSubDomains: true
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
7
packages/strapi/lib/middlewares/ip/defaults.json
Normal file
7
packages/strapi/lib/middlewares/ip/defaults.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"ip": {
|
||||
"enabled": false,
|
||||
"whiteList": [],
|
||||
"blackList": []
|
||||
}
|
||||
}
|
||||
@ -10,18 +10,6 @@
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
ip: {
|
||||
enabled: false,
|
||||
whiteList: [],
|
||||
blackList: []
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
9
packages/strapi/lib/middlewares/language/defaults.json
Normal file
9
packages/strapi/lib/middlewares/language/defaults.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"language": {
|
||||
"enabled": false,
|
||||
"defaultLocale": "en_us",
|
||||
"locales": ["en_us"],
|
||||
"modes": ["query", "subdomain", "cookie", "header", "url", "tld"],
|
||||
"cookieName": "locale"
|
||||
}
|
||||
}
|
||||
@ -13,20 +13,6 @@ const path = require('path');
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
language: {
|
||||
enabled: false,
|
||||
defaultLocale: 'en_us',
|
||||
locales: ['en_us'],
|
||||
modes: ['query', 'subdomain', 'cookie', 'header', 'url', 'tld'],
|
||||
cookieName: 'locale'
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
5
packages/strapi/lib/middlewares/logger/defaults.json
Normal file
5
packages/strapi/lib/middlewares/logger/defaults.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"logger": {
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
@ -6,16 +6,6 @@
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
logger: {
|
||||
enabled: true
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
6
packages/strapi/lib/middlewares/p3p/defaults.json
Normal file
6
packages/strapi/lib/middlewares/p3p/defaults.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"p3p": {
|
||||
"enabled": false,
|
||||
"value": ""
|
||||
}
|
||||
}
|
||||
@ -10,17 +10,6 @@
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
p3p: {
|
||||
enabled: false,
|
||||
value: ''
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
6
packages/strapi/lib/middlewares/parser/defaults.json
Normal file
6
packages/strapi/lib/middlewares/parser/defaults.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parser": {
|
||||
"enabled": true,
|
||||
"multipart": true
|
||||
}
|
||||
}
|
||||
@ -6,17 +6,6 @@
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
parser: {
|
||||
enabled: true,
|
||||
multipart: true
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
7
packages/strapi/lib/middlewares/public/defaults.json
Normal file
7
packages/strapi/lib/middlewares/public/defaults.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"public": {
|
||||
"enabled": true,
|
||||
"maxAge": 60000,
|
||||
"path": "./public"
|
||||
}
|
||||
}
|
||||
@ -17,18 +17,6 @@ const Koa = require('koa');
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
public: {
|
||||
enabled: true,
|
||||
maxAge: 60000,
|
||||
path: './public'
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
{
|
||||
"responseTime": {
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
@ -6,16 +6,6 @@
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
responseTime: {
|
||||
enabled: true
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
5
packages/strapi/lib/middlewares/responses/defaults.json
Normal file
5
packages/strapi/lib/middlewares/responses/defaults.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"responses": {
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
7
packages/strapi/lib/middlewares/router/defaults.json
Normal file
7
packages/strapi/lib/middlewares/router/defaults.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"router": {
|
||||
"enabled": true,
|
||||
"prefix": "",
|
||||
"routes": {}
|
||||
}
|
||||
}
|
||||
@ -16,18 +16,6 @@ module.exports = strapi => {
|
||||
const composeEndpoint = require('./utils/composeEndpoint')(strapi);
|
||||
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
router: {
|
||||
enabled: true,
|
||||
prefix: '',
|
||||
routes: {}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
18
packages/strapi/lib/middlewares/session/defaults.json
Normal file
18
packages/strapi/lib/middlewares/session/defaults.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"session": {
|
||||
"enabled": true,
|
||||
"client": "cookie",
|
||||
"key": "strapi.sid",
|
||||
"prefix": "strapi:sess:",
|
||||
"ttl": 864000000,
|
||||
"rolling": false,
|
||||
"secretKeys": ["mySecretKey1", "mySecretKey2"],
|
||||
"cookie": {
|
||||
"path": "/",
|
||||
"httpOnly": true,
|
||||
"maxAge": 864000000,
|
||||
"rewrite": true,
|
||||
"signed": false
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -16,29 +16,6 @@ const _ = require('lodash');
|
||||
|
||||
module.exports = strapi => {
|
||||
const hook = {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
session: {
|
||||
enabled: true,
|
||||
client: 'cookie',
|
||||
key: 'strapi.sid',
|
||||
prefix: 'strapi:sess:',
|
||||
ttl: 24 * 60 * 60 * 1000, // One day in ms
|
||||
rolling: false,
|
||||
secretKeys: ['mySecretKey1', 'mySecretKey2'],
|
||||
cookie: {
|
||||
path: '/',
|
||||
httpOnly: true,
|
||||
maxAge: 24 * 60 * 60 * 1000, // One day in ms
|
||||
rewrite: true,
|
||||
signed: false
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
6
packages/strapi/lib/middlewares/xframe/defaults.json
Normal file
6
packages/strapi/lib/middlewares/xframe/defaults.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"xframe": {
|
||||
"enabled": true,
|
||||
"value": "SAMEORIGIN"
|
||||
}
|
||||
}
|
||||
@ -10,17 +10,6 @@
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
xframe: {
|
||||
enabled: true,
|
||||
value: 'SAMEORIGIN'
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
6
packages/strapi/lib/middlewares/xss/defaults.json
Normal file
6
packages/strapi/lib/middlewares/xss/defaults.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"xss": {
|
||||
"enabled": false,
|
||||
"mode": "block"
|
||||
}
|
||||
}
|
||||
@ -10,17 +10,6 @@
|
||||
|
||||
module.exports = strapi => {
|
||||
return {
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
|
||||
defaults: {
|
||||
xss: {
|
||||
enabled: false,
|
||||
mode: 'block'
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user