@strapi/strapi 4.0.5 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/strapi.js +11 -11
- package/lib/Strapi.js +4 -6
- package/lib/middlewares/index.js +2 -2
- package/lib/middlewares/session.js +28 -0
- package/lib/services/entity-service/params.js +1 -1
- package/lib/services/fs.js +1 -1
- package/lib/services/server/index.js +4 -1
- package/lib/services/server/koa.js +2 -1
- package/lib/services/server/middleware.js +12 -3
- package/lib/services/server/register-middlewares.js +1 -0
- package/package.json +13 -13
- package/lib/middlewares/session/defaults.json +0 -18
- package/lib/middlewares/session/index.js +0 -140
package/bin/strapi.js
CHANGED
|
@@ -17,7 +17,7 @@ const checkCwdIsStrapiApp = name => {
|
|
|
17
17
|
console.log(
|
|
18
18
|
`You need to run ${yellow(
|
|
19
19
|
`strapi ${name}`
|
|
20
|
-
)} in a Strapi project. Make sure you are in the right directory
|
|
20
|
+
)} in a Strapi project. Make sure you are in the right directory.`
|
|
21
21
|
);
|
|
22
22
|
process.exit(1);
|
|
23
23
|
};
|
|
@@ -40,7 +40,7 @@ const getLocalScript = name => (...args) => {
|
|
|
40
40
|
console.log(
|
|
41
41
|
`Error loading the local ${yellow(
|
|
42
42
|
name
|
|
43
|
-
)} command. Strapi might not be installed in your "node_modules". You may need to run "
|
|
43
|
+
)} command. Strapi might not be installed in your "node_modules". You may need to run "yarn install".`
|
|
44
44
|
);
|
|
45
45
|
process.exit(1);
|
|
46
46
|
}
|
|
@@ -67,7 +67,7 @@ program.addHelpCommand('help [command]', 'Display help for command');
|
|
|
67
67
|
program.version(packageJSON.version, '-v, --version', 'Output the version number');
|
|
68
68
|
program
|
|
69
69
|
.command('version')
|
|
70
|
-
.description('Output
|
|
70
|
+
.description('Output the version of Strapi')
|
|
71
71
|
.action(() => {
|
|
72
72
|
process.stdout.write(packageJSON.version + '\n');
|
|
73
73
|
process.exit(0);
|
|
@@ -84,8 +84,8 @@ program
|
|
|
84
84
|
.command('new <directory>')
|
|
85
85
|
.option('--no-run', 'Do not start the application after it is created')
|
|
86
86
|
.option('--use-npm', 'Force usage of npm instead of yarn to create the project')
|
|
87
|
-
.option('--debug', 'Display database connection
|
|
88
|
-
.option('--quickstart', '
|
|
87
|
+
.option('--debug', 'Display database connection errors')
|
|
88
|
+
.option('--quickstart', 'Create quickstart app')
|
|
89
89
|
.option('--dbclient <dbclient>', 'Database client')
|
|
90
90
|
.option('--dbhost <dbhost>', 'Database host')
|
|
91
91
|
.option('--dbport <dbport>', 'Database port')
|
|
@@ -94,7 +94,7 @@ program
|
|
|
94
94
|
.option('--dbpassword <dbpassword>', 'Database password')
|
|
95
95
|
.option('--dbssl <dbssl>', 'Database SSL')
|
|
96
96
|
.option('--dbfile <dbfile>', 'Database file path for sqlite')
|
|
97
|
-
.option('--dbforce', '
|
|
97
|
+
.option('--dbforce', 'Allow overwriting existing database content')
|
|
98
98
|
.description('Create a new application')
|
|
99
99
|
.action(require('../lib/commands/new'));
|
|
100
100
|
|
|
@@ -110,7 +110,7 @@ program
|
|
|
110
110
|
.alias('dev')
|
|
111
111
|
.option('--no-build', 'Disable build')
|
|
112
112
|
.option('--watch-admin', 'Enable watch', false)
|
|
113
|
-
.option('--polling', '
|
|
113
|
+
.option('--polling', 'Watch for file changes in network directories', false)
|
|
114
114
|
.option('--browser <name>', 'Open the browser', true)
|
|
115
115
|
.description('Start your Strapi application in development mode')
|
|
116
116
|
.action(getLocalScript('develop'));
|
|
@@ -118,7 +118,7 @@ program
|
|
|
118
118
|
// $ strapi generate
|
|
119
119
|
program
|
|
120
120
|
.command('generate')
|
|
121
|
-
.description('Launch interactive API generator')
|
|
121
|
+
.description('Launch the interactive API generator')
|
|
122
122
|
.action(() => {
|
|
123
123
|
checkCwdIsStrapiApp('generate');
|
|
124
124
|
process.argv.splice(2, 1);
|
|
@@ -133,8 +133,8 @@ program
|
|
|
133
133
|
|
|
134
134
|
program
|
|
135
135
|
.command('build')
|
|
136
|
-
.option('--no-optimization', 'Build the
|
|
137
|
-
.description('
|
|
136
|
+
.option('--no-optimization', 'Build the admin app without optimizing assets')
|
|
137
|
+
.description('Build the strapi admin app')
|
|
138
138
|
.action(getLocalScript('build'));
|
|
139
139
|
|
|
140
140
|
// `$ strapi install`
|
|
@@ -154,7 +154,7 @@ program
|
|
|
154
154
|
program
|
|
155
155
|
.command('watch-admin')
|
|
156
156
|
.option('--browser <name>', 'Open the browser', true)
|
|
157
|
-
.description('
|
|
157
|
+
.description('Start the admin development server')
|
|
158
158
|
.action(getLocalScript('watchAdmin'));
|
|
159
159
|
|
|
160
160
|
program
|
package/lib/Strapi.js
CHANGED
|
@@ -189,15 +189,13 @@ class Strapi {
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
sendStartupTelemetry() {
|
|
192
|
-
// Get database clients
|
|
193
|
-
const databaseClients = _.map(this.config.get('connections'), _.property('settings.client'));
|
|
194
|
-
|
|
195
192
|
// Emit started event.
|
|
196
193
|
// do not await to avoid slower startup
|
|
197
194
|
this.telemetry.send('didStartServer', {
|
|
198
|
-
database:
|
|
199
|
-
plugins:
|
|
200
|
-
|
|
195
|
+
database: strapi.config.get('database.connection.client'),
|
|
196
|
+
plugins: Object.keys(strapi.plugins),
|
|
197
|
+
// TODO: to add back
|
|
198
|
+
// providers: this.config.installedProviders,
|
|
201
199
|
});
|
|
202
200
|
}
|
|
203
201
|
|
package/lib/middlewares/index.js
CHANGED
|
@@ -12,8 +12,7 @@ const query = require('./query');
|
|
|
12
12
|
const responseTime = require('./response-time');
|
|
13
13
|
const responses = require('./responses');
|
|
14
14
|
const security = require('./security');
|
|
15
|
-
|
|
16
|
-
// session: require('./session'),
|
|
15
|
+
const session = require('./session');
|
|
17
16
|
const publicStatic = require('./public');
|
|
18
17
|
|
|
19
18
|
module.exports = {
|
|
@@ -23,6 +22,7 @@ module.exports = {
|
|
|
23
22
|
cors,
|
|
24
23
|
responseTime,
|
|
25
24
|
poweredBy,
|
|
25
|
+
session,
|
|
26
26
|
logger,
|
|
27
27
|
compression,
|
|
28
28
|
responses,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { defaultsDeep, isEmpty, isArray } = require('lodash/fp');
|
|
4
|
+
const session = require('koa-session');
|
|
5
|
+
|
|
6
|
+
const defaultConfig = {
|
|
7
|
+
key: 'koa.sess',
|
|
8
|
+
maxAge: 86400000,
|
|
9
|
+
autoCommit: true,
|
|
10
|
+
overwrite: true,
|
|
11
|
+
httpOnly: true,
|
|
12
|
+
signed: true,
|
|
13
|
+
rolling: false,
|
|
14
|
+
renew: false,
|
|
15
|
+
secure: process.env.NODE_ENV === 'production' ? true : false,
|
|
16
|
+
sameSite: null,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
module.exports = (userConfig, { strapi }) => {
|
|
20
|
+
const keys = strapi.server.app.keys;
|
|
21
|
+
if (!isArray(keys) || isEmpty(keys) || keys.some(isEmpty)) {
|
|
22
|
+
throw new Error(`App keys are required. Please set app.keys in config/server.js (ex: keys: ['myKeyA', 'myKeyB'])`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const config = defaultsDeep(defaultConfig, userConfig);
|
|
26
|
+
|
|
27
|
+
strapi.server.use(session(config, strapi.server.app));
|
|
28
|
+
};
|
package/lib/services/fs.js
CHANGED
|
@@ -12,7 +12,7 @@ module.exports = strapi => {
|
|
|
12
12
|
|
|
13
13
|
const normalizedPath = path.normalize(filePath).replace(/^\/?(\.\/|\.\.\/)+/, '');
|
|
14
14
|
|
|
15
|
-
return path.
|
|
15
|
+
return path.resolve(strapi.dirs.root, normalizedPath);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const strapiFS = {
|
|
@@ -28,7 +28,10 @@ const healthCheck = async ctx => {
|
|
|
28
28
|
* @returns {Server}
|
|
29
29
|
*/
|
|
30
30
|
const createServer = strapi => {
|
|
31
|
-
const app = createKoaApp({
|
|
31
|
+
const app = createKoaApp({
|
|
32
|
+
proxy: strapi.config.get('server.proxy'),
|
|
33
|
+
keys: strapi.config.get('server.app.keys'),
|
|
34
|
+
});
|
|
32
35
|
|
|
33
36
|
const router = new Router();
|
|
34
37
|
|
|
@@ -5,6 +5,14 @@ const { propOr, isArray, isNil } = require('lodash/fp');
|
|
|
5
5
|
|
|
6
6
|
const getMiddlewareConfig = propOr([], 'config.middlewares');
|
|
7
7
|
|
|
8
|
+
const instantiateMiddleware = (middlewareFactory, name, config, strapi) => {
|
|
9
|
+
try {
|
|
10
|
+
return middlewareFactory(config, { strapi });
|
|
11
|
+
} catch (e) {
|
|
12
|
+
throw new Error(`Middleware "${name}": ${e.message}`);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
8
16
|
const resolveRouteMiddlewares = (route, strapi) => {
|
|
9
17
|
const middlewaresConfig = getMiddlewareConfig(route);
|
|
10
18
|
|
|
@@ -45,7 +53,7 @@ const resolveMiddlewares = (config, strapi) => {
|
|
|
45
53
|
|
|
46
54
|
middlewares.push({
|
|
47
55
|
name: item,
|
|
48
|
-
handler: middlewareFactory
|
|
56
|
+
handler: instantiateMiddleware(middlewareFactory, item, {}, strapi),
|
|
49
57
|
});
|
|
50
58
|
|
|
51
59
|
continue;
|
|
@@ -58,16 +66,17 @@ const resolveMiddlewares = (config, strapi) => {
|
|
|
58
66
|
const middlewareFactory = strapi.middleware(name);
|
|
59
67
|
middlewares.push({
|
|
60
68
|
name,
|
|
61
|
-
handler: middlewareFactory
|
|
69
|
+
handler: instantiateMiddleware(middlewareFactory, name, config, strapi),
|
|
62
70
|
});
|
|
63
71
|
|
|
64
72
|
continue;
|
|
65
73
|
}
|
|
66
74
|
|
|
67
75
|
if (resolve) {
|
|
76
|
+
const resolvedMiddlewareFactory = resolveCustomMiddleware(resolve, strapi);
|
|
68
77
|
middlewares.push({
|
|
69
78
|
name: resolve,
|
|
70
|
-
handler:
|
|
79
|
+
handler: instantiateMiddleware(resolvedMiddlewareFactory, item, config, strapi),
|
|
71
80
|
});
|
|
72
81
|
|
|
73
82
|
continue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/strapi",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -80,16 +80,16 @@
|
|
|
80
80
|
"dependencies": {
|
|
81
81
|
"@koa/cors": "3.1.0",
|
|
82
82
|
"@koa/router": "10.1.1",
|
|
83
|
-
"@strapi/admin": "4.0
|
|
84
|
-
"@strapi/database": "4.0
|
|
85
|
-
"@strapi/generate-new": "4.0
|
|
86
|
-
"@strapi/generators": "4.0
|
|
87
|
-
"@strapi/logger": "4.0
|
|
88
|
-
"@strapi/plugin-content-manager": "4.0
|
|
89
|
-
"@strapi/plugin-content-type-builder": "4.0
|
|
90
|
-
"@strapi/plugin-email": "4.0
|
|
91
|
-
"@strapi/plugin-upload": "4.0
|
|
92
|
-
"@strapi/utils": "4.0
|
|
83
|
+
"@strapi/admin": "4.1.0",
|
|
84
|
+
"@strapi/database": "4.1.0",
|
|
85
|
+
"@strapi/generate-new": "4.1.0",
|
|
86
|
+
"@strapi/generators": "4.1.0",
|
|
87
|
+
"@strapi/logger": "4.1.0",
|
|
88
|
+
"@strapi/plugin-content-manager": "4.1.0",
|
|
89
|
+
"@strapi/plugin-content-type-builder": "4.1.0",
|
|
90
|
+
"@strapi/plugin-email": "4.1.0",
|
|
91
|
+
"@strapi/plugin-upload": "4.1.0",
|
|
92
|
+
"@strapi/utils": "4.1.0",
|
|
93
93
|
"bcryptjs": "2.4.3",
|
|
94
94
|
"boxen": "5.1.2",
|
|
95
95
|
"chalk": "4.1.2",
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
"koa-session": "6.2.0",
|
|
118
118
|
"koa-static": "5.0.0",
|
|
119
119
|
"lodash": "4.17.21",
|
|
120
|
-
"node-fetch": "2.6.
|
|
120
|
+
"node-fetch": "2.6.7",
|
|
121
121
|
"node-machine-id": "1.1.12",
|
|
122
122
|
"node-schedule": "2.0.0",
|
|
123
123
|
"open": "8.2.1",
|
|
@@ -136,5 +136,5 @@
|
|
|
136
136
|
"node": ">=12.22.0 <=16.x.x",
|
|
137
137
|
"npm": ">=6.0.0"
|
|
138
138
|
},
|
|
139
|
-
"gitHead": "
|
|
139
|
+
"gitHead": "d4273d81fbeec230b5734375e43a5f1f1f2a0231"
|
|
140
140
|
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"session": {
|
|
3
|
-
"enabled": true,
|
|
4
|
-
"client": "cookie",
|
|
5
|
-
"key": "strapi.sid",
|
|
6
|
-
"prefix": "strapi:sess:",
|
|
7
|
-
"ttl": 864000000,
|
|
8
|
-
"rolling": false,
|
|
9
|
-
"secretKeys": ["mySecretKey1", "mySecretKey2"],
|
|
10
|
-
"cookie": {
|
|
11
|
-
"path": "/",
|
|
12
|
-
"httpOnly": true,
|
|
13
|
-
"maxAge": 864000000,
|
|
14
|
-
"rewrite": true,
|
|
15
|
-
"signed": false
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const _ = require('lodash');
|
|
5
|
-
const session = require('koa-session');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Session middleware
|
|
9
|
-
*/
|
|
10
|
-
module.exports = strapi => {
|
|
11
|
-
const requireStore = store => {
|
|
12
|
-
return require(path.resolve(strapi.dirs.root, 'node_modules', 'koa-' + store));
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const defineStore = session => {
|
|
16
|
-
if (_.isEmpty(_.get(session, 'client'))) {
|
|
17
|
-
return strapi.log.error(
|
|
18
|
-
'(middleware:session) please provide a valid client to store session'
|
|
19
|
-
);
|
|
20
|
-
} else if (_.isEmpty(_.get(session, 'connection'))) {
|
|
21
|
-
return strapi.log.error(
|
|
22
|
-
'(middleware:session) please provide connection for the session store'
|
|
23
|
-
);
|
|
24
|
-
} else if (!strapi.config.get(`database.connections.${session.connection}`)) {
|
|
25
|
-
return strapi.log.error(
|
|
26
|
-
'(middleware:session) please provide a valid connection for the session store'
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
session.settings = strapi.config.get(`database.connections.${session.connection}`);
|
|
31
|
-
|
|
32
|
-
// Define correct store name to avoid require to failed.
|
|
33
|
-
switch (session.client.toLowerCase()) {
|
|
34
|
-
case 'redis': {
|
|
35
|
-
const store = requireStore('redis');
|
|
36
|
-
|
|
37
|
-
session.settings.db = session.settings.database;
|
|
38
|
-
|
|
39
|
-
return store(session.settings);
|
|
40
|
-
}
|
|
41
|
-
case 'mysql': {
|
|
42
|
-
const Store = requireStore('mysql-session');
|
|
43
|
-
|
|
44
|
-
return new Store(session.settings);
|
|
45
|
-
}
|
|
46
|
-
case 'mongo': {
|
|
47
|
-
const Store = requireStore('generic-session-mongo');
|
|
48
|
-
|
|
49
|
-
session.settings.db = session.settings.database;
|
|
50
|
-
|
|
51
|
-
return new Store(session.settings);
|
|
52
|
-
}
|
|
53
|
-
case 'postgresql': {
|
|
54
|
-
const Store = requireStore('pg-session');
|
|
55
|
-
|
|
56
|
-
return new Store(session.settings, session.options);
|
|
57
|
-
}
|
|
58
|
-
case 'rethink': {
|
|
59
|
-
const Store = requireStore('generic-session-rethinkdb');
|
|
60
|
-
|
|
61
|
-
session.settings.dbName = session.settings.database;
|
|
62
|
-
session.settings.tableName = session.settings.table;
|
|
63
|
-
|
|
64
|
-
const sessionStore = new Store({
|
|
65
|
-
connection: session.settings,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// Create the DB, tables and indexes to store sessions.
|
|
69
|
-
sessionStore.setup();
|
|
70
|
-
|
|
71
|
-
return sessionStore;
|
|
72
|
-
}
|
|
73
|
-
case 'sqlite': {
|
|
74
|
-
const Store = requireStore('sqlite3-session');
|
|
75
|
-
|
|
76
|
-
return new Store(session.fileName, session.options);
|
|
77
|
-
}
|
|
78
|
-
case 'sequelize': {
|
|
79
|
-
const Store = requireStore('generic-session-sequelize');
|
|
80
|
-
|
|
81
|
-
// Sequelize needs to be instantiated.
|
|
82
|
-
if (!_.isObject(strapi.sequelize)) {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return new Store(strapi.sequelize, session.options);
|
|
87
|
-
}
|
|
88
|
-
default: {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
initialize() {
|
|
96
|
-
strapi.server.app.keys = strapi.config.get('middleware.settings.session.secretKeys');
|
|
97
|
-
|
|
98
|
-
if (
|
|
99
|
-
_.has(strapi.config.middleware.settings.session, 'client') &&
|
|
100
|
-
_.isString(strapi.config.middleware.settings.session.client) &&
|
|
101
|
-
strapi.config.middleware.settings.session.client !== 'cookie'
|
|
102
|
-
) {
|
|
103
|
-
const store = defineStore(strapi.config.middleware.settings.session);
|
|
104
|
-
|
|
105
|
-
if (!_.isEmpty(store)) {
|
|
106
|
-
// Options object contains the defined store, the custom middlewares configurations
|
|
107
|
-
// and also the function which are located to `./config/functions/session.js`
|
|
108
|
-
const options = _.assign(
|
|
109
|
-
{
|
|
110
|
-
store,
|
|
111
|
-
},
|
|
112
|
-
strapi.config.middleware.settings.session
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
strapi.server.use(session(options, strapi.server.app));
|
|
116
|
-
strapi.server.use((ctx, next) => {
|
|
117
|
-
ctx.state = ctx.state || {};
|
|
118
|
-
ctx.state.session = ctx.session || {};
|
|
119
|
-
|
|
120
|
-
return next();
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
} else if (
|
|
124
|
-
_.has(strapi.config.middleware.settings.session, 'client') &&
|
|
125
|
-
_.isString(strapi.config.middleware.settings.session.client) &&
|
|
126
|
-
strapi.config.middleware.settings.session.client === 'cookie'
|
|
127
|
-
) {
|
|
128
|
-
const options = _.assign(strapi.config.middleware.settings.session);
|
|
129
|
-
|
|
130
|
-
strapi.server.use(session(options, strapi.server.app));
|
|
131
|
-
strapi.server.use((ctx, next) => {
|
|
132
|
-
ctx.state = ctx.state || {};
|
|
133
|
-
ctx.state.session = ctx.session || {};
|
|
134
|
-
|
|
135
|
-
return next();
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
};
|
|
140
|
-
};
|