@strapi/strapi 4.0.4 → 4.0.8
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/commands/develop.js +1 -1
- package/lib/core/loaders/plugins/index.js +0 -12
- 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/metrics/sender.js +2 -2
- 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/policy.js +2 -2
- package/lib/services/server/register-middlewares.js +1 -0
- package/lib/utils/machine-id.js +14 -0
- package/lib/utils/success.js +2 -2
- package/package.json +15 -14
- 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/commands/develop.js
CHANGED
|
@@ -22,7 +22,7 @@ module.exports = async function({ build, watchAdmin, polling, browser }) {
|
|
|
22
22
|
const logger = createLogger(config.logger, {});
|
|
23
23
|
|
|
24
24
|
try {
|
|
25
|
-
if (cluster.isMaster) {
|
|
25
|
+
if (cluster.isMaster || cluster.isPrimary) {
|
|
26
26
|
const serveAdminPanel = getOr(true, 'admin.serveAdminPanel')(config);
|
|
27
27
|
|
|
28
28
|
const buildExists = fs.existsSync(path.join(dir, 'build'));
|
|
@@ -55,17 +55,6 @@ const applyUserExtension = async plugins => {
|
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
const formatContentTypes = plugins => {
|
|
59
|
-
for (const pluginName in plugins) {
|
|
60
|
-
const plugin = plugins[pluginName];
|
|
61
|
-
for (const contentTypeName in plugin.contentTypes) {
|
|
62
|
-
const ctSchema = plugin.contentTypes[contentTypeName].schema;
|
|
63
|
-
ctSchema.plugin = pluginName;
|
|
64
|
-
ctSchema.uid = `plugin::${pluginName}.${ctSchema.singularName}`;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
58
|
const applyUserConfig = async plugins => {
|
|
70
59
|
const userPluginsConfig = await getUserPluginsConfig();
|
|
71
60
|
|
|
@@ -111,7 +100,6 @@ const loadPlugins = async strapi => {
|
|
|
111
100
|
// TODO: validate plugin format
|
|
112
101
|
await applyUserConfig(plugins);
|
|
113
102
|
await applyUserExtension(plugins);
|
|
114
|
-
formatContentTypes(plugins);
|
|
115
103
|
|
|
116
104
|
for (const pluginName in plugins) {
|
|
117
105
|
strapi.container.get('plugins').add(pluginName, plugins[pluginName]);
|
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 = {
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
const os = require('os');
|
|
4
4
|
const _ = require('lodash');
|
|
5
5
|
const isDocker = require('is-docker');
|
|
6
|
-
const { machineIdSync } = require('node-machine-id');
|
|
7
6
|
const fetch = require('node-fetch');
|
|
8
7
|
const ciEnv = require('ci-info');
|
|
9
8
|
const ee = require('../../utils/ee');
|
|
9
|
+
const machineID = require('../../utils/machine-id');
|
|
10
10
|
const stringifyDeep = require('./stringify-deep');
|
|
11
11
|
|
|
12
12
|
const defaultQueryOpts = {
|
|
@@ -33,7 +33,7 @@ const addPackageJsonStrapiMetadata = (metadata, strapi) => {
|
|
|
33
33
|
*/
|
|
34
34
|
module.exports = strapi => {
|
|
35
35
|
const { uuid } = strapi.config;
|
|
36
|
-
const deviceId =
|
|
36
|
+
const deviceId = machineID();
|
|
37
37
|
const isEE = strapi.EE === true && ee.isEE === true;
|
|
38
38
|
|
|
39
39
|
const anonymous_metadata = {
|
|
@@ -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;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const { propOr } = require('lodash/fp');
|
|
4
|
-
const {
|
|
4
|
+
const { PolicyError } = require('@strapi/utils').errors;
|
|
5
5
|
const { policy: policyUtils } = require('@strapi/utils');
|
|
6
6
|
|
|
7
7
|
const getPoliciesConfig = propOr([], 'config.policies');
|
|
@@ -17,7 +17,7 @@ const resolvePolicies = route => {
|
|
|
17
17
|
const result = await handler(context, config, { strapi });
|
|
18
18
|
|
|
19
19
|
if (![true, undefined].includes(result)) {
|
|
20
|
-
throw new
|
|
20
|
+
throw new PolicyError();
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { machineIdSync } = require('node-machine-id');
|
|
4
|
+
const uuid = require('uuid');
|
|
5
|
+
|
|
6
|
+
module.exports = () => {
|
|
7
|
+
try {
|
|
8
|
+
const deviceId = machineIdSync();
|
|
9
|
+
return deviceId;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
const deviceId = uuid();
|
|
12
|
+
return deviceId;
|
|
13
|
+
}
|
|
14
|
+
};
|
package/lib/utils/success.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
const fetch = require('node-fetch');
|
|
8
|
-
const
|
|
8
|
+
const machineID = require('./machine-id');
|
|
9
9
|
|
|
10
10
|
/*
|
|
11
11
|
* No need to worry about this file, we only retrieve anonymous data here.
|
|
@@ -21,7 +21,7 @@ try {
|
|
|
21
21
|
method: 'POST',
|
|
22
22
|
body: JSON.stringify({
|
|
23
23
|
event: 'didInstallStrapi',
|
|
24
|
-
deviceId:
|
|
24
|
+
deviceId: machineID(),
|
|
25
25
|
}),
|
|
26
26
|
headers: { 'Content-Type': 'application/json' },
|
|
27
27
|
}).catch(() => {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/strapi",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.8",
|
|
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.0.8",
|
|
84
|
+
"@strapi/database": "4.0.8",
|
|
85
|
+
"@strapi/generate-new": "4.0.8",
|
|
86
|
+
"@strapi/generators": "4.0.8",
|
|
87
|
+
"@strapi/logger": "4.0.8",
|
|
88
|
+
"@strapi/plugin-content-manager": "4.0.8",
|
|
89
|
+
"@strapi/plugin-content-type-builder": "4.0.8",
|
|
90
|
+
"@strapi/plugin-email": "4.0.8",
|
|
91
|
+
"@strapi/plugin-upload": "4.0.8",
|
|
92
|
+
"@strapi/utils": "4.0.8",
|
|
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",
|
|
@@ -126,7 +126,8 @@
|
|
|
126
126
|
"qs": "6.10.1",
|
|
127
127
|
"resolve-cwd": "3.0.0",
|
|
128
128
|
"semver": "7.3.5",
|
|
129
|
-
"statuses": "2.0.1"
|
|
129
|
+
"statuses": "2.0.1",
|
|
130
|
+
"uuid": "^3.3.2"
|
|
130
131
|
},
|
|
131
132
|
"devDependencies": {
|
|
132
133
|
"supertest": "^6.1.6"
|
|
@@ -135,5 +136,5 @@
|
|
|
135
136
|
"node": ">=12.22.0 <=16.x.x",
|
|
136
137
|
"npm": ">=6.0.0"
|
|
137
138
|
},
|
|
138
|
-
"gitHead": "
|
|
139
|
+
"gitHead": "669bb2f0440d3b21a23c8d665fdba98bd3d8cc71"
|
|
139
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
|
-
};
|