Use default config middleware and load plugins middlewares

This commit is contained in:
Jim Laurie 2017-11-24 15:15:02 +01:00
parent 6d253cef87
commit a2c8e212fc
46 changed files with 225 additions and 266 deletions

View File

@ -0,0 +1,5 @@
{
"views": {
"enabled": false
}
}

View File

@ -18,16 +18,6 @@ const views = require('koa-views');
module.exports = strapi => {
return {
/**
* Default options
*/
defaults: {
views: {
enabled: false
}
},
/**
* Initialize the hook
*/

View File

@ -0,0 +1,5 @@
{
"users-permissions": {
"enabled": true
}
}

View File

@ -0,0 +1,11 @@
module.exports = strapi => {
return {
initialize: function(cb) {
strapi.app.use(async (ctx, next) => {
await next();
});
cb();
}
};
};

View File

@ -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"
}
}

View File

@ -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')) {

View File

@ -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();
}),

View File

@ -0,0 +1,5 @@
{
"boom": {
"enabled": true
}
}

View File

@ -11,16 +11,6 @@ const delegate = require('delegates');
module.exports = strapi => {
return {
/**
* Default options
*/
defaults: {
boom: {
enabled: true
}
},
/**
* Initialize the hook
*/

View 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
}
}

View File

@ -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
*/

View File

@ -0,0 +1,5 @@
{
"cron": {
"enabled": false
}
}

View File

@ -14,16 +14,6 @@ const cron = require('node-schedule');
module.exports = strapi => {
return {
/**
* Default options
*/
defaults: {
cron: {
enabled: false
}
},
/**
* Initialize the hook
*/

View File

@ -0,0 +1,5 @@
{
"csp": {
"enabled": false
}
}

View File

@ -10,16 +10,6 @@
module.exports = strapi => {
return {
/**
* Default options
*/
defaults: {
csp: {
enabled: false
}
},
/**
* Initialize the hook
*/

View File

@ -0,0 +1,7 @@
{
"csrf": {
"enabled": false,
"key": "_csrf",
"secret": "_csrfSecret"
}
}

View File

@ -10,18 +10,6 @@
module.exports = strapi => {
return {
/**
* Default options
*/
defaults: {
csrf: {
enabled: false,
key: '_csrf',
secret: '_csrfSecret'
}
},
/**
* Initialize the hook
*/

View File

@ -0,0 +1,6 @@
{
"favicon": {
"path": "favicon.ico",
"maxAge": 86400000
}
}

View File

@ -13,17 +13,6 @@ const path = require('path');
module.exports = strapi => {
return {
/**
* Default options
*/
defaults: {
favicon: {
path: 'favicon.ico',
maxAge: 86400000
}
},
/**
* Initialize the hook
*/

View File

@ -0,0 +1,5 @@
{
"gzip": {
"enabled": false
}
}

View File

@ -6,16 +6,6 @@
module.exports = strapi => {
return {
/**
* Default options
*/
defaults: {
gzip: {
enabled: false
}
},
/**
* Initialize the hook
*/

View File

@ -0,0 +1,7 @@
{
"hsts": {
"enabled": true,
"maxAge": 31536000,
"includeSubDomains": true
}
}

View File

@ -10,18 +10,6 @@
module.exports = strapi => {
return {
/**
* Default options
*/
defaults: {
hsts: {
enabled: true,
maxAge: 31536000,
includeSubDomains: true
}
},
/**
* Initialize the hook
*/

View File

@ -0,0 +1,7 @@
{
"ip": {
"enabled": false,
"whiteList": [],
"blackList": []
}
}

View File

@ -10,18 +10,6 @@
module.exports = strapi => {
return {
/**
* Default options
*/
defaults: {
ip: {
enabled: false,
whiteList: [],
blackList: []
}
},
/**
* Initialize the hook
*/

View File

@ -0,0 +1,9 @@
{
"language": {
"enabled": false,
"defaultLocale": "en_us",
"locales": ["en_us"],
"modes": ["query", "subdomain", "cookie", "header", "url", "tld"],
"cookieName": "locale"
}
}

View File

@ -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
*/

View File

@ -0,0 +1,5 @@
{
"logger": {
"enabled": true
}
}

View File

@ -6,16 +6,6 @@
module.exports = strapi => {
return {
/**
* Default options
*/
defaults: {
logger: {
enabled: true
}
},
/**
* Initialize the hook
*/

View File

@ -0,0 +1,6 @@
{
"p3p": {
"enabled": false,
"value": ""
}
}

View File

@ -10,17 +10,6 @@
module.exports = strapi => {
return {
/**
* Default options
*/
defaults: {
p3p: {
enabled: false,
value: ''
}
},
/**
* Initialize the hook
*/

View File

@ -0,0 +1,6 @@
{
"parser": {
"enabled": true,
"multipart": true
}
}

View File

@ -6,17 +6,6 @@
module.exports = strapi => {
return {
/**
* Default options
*/
defaults: {
parser: {
enabled: true,
multipart: true
}
},
/**
* Initialize the hook
*/

View File

@ -0,0 +1,7 @@
{
"public": {
"enabled": true,
"maxAge": 60000,
"path": "./public"
}
}

View File

@ -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
*/

View File

@ -0,0 +1,5 @@
{
"responseTime": {
"enabled": true
}
}

View File

@ -6,16 +6,6 @@
module.exports = strapi => {
return {
/**
* Default options
*/
defaults: {
responseTime: {
enabled: true
}
},
/**
* Initialize the hook
*/

View File

@ -0,0 +1,5 @@
{
"responses": {
"enabled": true
}
}

View File

@ -0,0 +1,7 @@
{
"router": {
"enabled": true,
"prefix": "",
"routes": {}
}
}

View File

@ -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
*/

View 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
}
}
}

View File

@ -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
*/

View File

@ -0,0 +1,6 @@
{
"xframe": {
"enabled": true,
"value": "SAMEORIGIN"
}
}

View File

@ -10,17 +10,6 @@
module.exports = strapi => {
return {
/**
* Default options
*/
defaults: {
xframe: {
enabled: true,
value: 'SAMEORIGIN'
}
},
/**
* Initialize the hook
*/

View File

@ -0,0 +1,6 @@
{
"xss": {
"enabled": false,
"mode": "block"
}
}

View File

@ -10,17 +10,6 @@
module.exports = strapi => {
return {
/**
* Default options
*/
defaults: {
xss: {
enabled: false,
mode: 'block'
}
},
/**
* Initialize the hook
*/