@midwayjs/express-session 3.15.8 → 3.15.11
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/README.md +34 -0
- package/dist/store.d.ts +1 -1
- package/dist/store.js +11 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -67,6 +67,40 @@ export class AutoConfiguration {
|
|
|
67
67
|
}
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
Another example for [connect-redis](https://github.com/tj/connect-redis).
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { Configuration, Inject } from '@midwayjs/core';
|
|
74
|
+
import * as session from '@midwayjs/express-session';
|
|
75
|
+
import RedisStore from "connect-redis"
|
|
76
|
+
import {createClient} from "redis"
|
|
77
|
+
|
|
78
|
+
// Initialize client.
|
|
79
|
+
let redisClient = createClient()
|
|
80
|
+
redisClient.connect().catch(console.error)
|
|
81
|
+
|
|
82
|
+
@Configuration({
|
|
83
|
+
imports: [
|
|
84
|
+
express,
|
|
85
|
+
session,
|
|
86
|
+
],
|
|
87
|
+
//...
|
|
88
|
+
})
|
|
89
|
+
export class AutoConfiguration {
|
|
90
|
+
@Inject()
|
|
91
|
+
sessionStoreManager: session.SessionStoreManager;
|
|
92
|
+
|
|
93
|
+
async onReady() {
|
|
94
|
+
// Initialize store.
|
|
95
|
+
this.sessionStoreManager.setSessionStore(RedisStore, {
|
|
96
|
+
client: redisClient,
|
|
97
|
+
prefix: "myapp:",
|
|
98
|
+
// ...
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
70
104
|
## Questions & Suggestions
|
|
71
105
|
|
|
72
106
|
Please open an issue [here](https://github.com/midwayjs/midway/issues/).
|
package/dist/store.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export declare class SessionStoreManager {
|
|
|
2
2
|
private sessionStoreClz;
|
|
3
3
|
private sessionStore;
|
|
4
4
|
private sessionStoreOptions;
|
|
5
|
-
setSessionStore(sessionStore: any, options
|
|
5
|
+
setSessionStore(sessionStore: any, options?: {}): void;
|
|
6
6
|
getSessionStore(session?: any): any;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=store.d.ts.map
|
package/dist/store.js
CHANGED
|
@@ -9,13 +9,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.SessionStoreManager = void 0;
|
|
10
10
|
const core_1 = require("@midwayjs/core");
|
|
11
11
|
let SessionStoreManager = class SessionStoreManager {
|
|
12
|
-
setSessionStore(sessionStore, options) {
|
|
12
|
+
setSessionStore(sessionStore, options = {}) {
|
|
13
13
|
this.sessionStoreClz = sessionStore;
|
|
14
14
|
this.sessionStoreOptions = options;
|
|
15
15
|
}
|
|
16
16
|
getSessionStore(session) {
|
|
17
17
|
if (!this.sessionStore && this.sessionStoreClz) {
|
|
18
|
-
|
|
18
|
+
if (core_1.Types.isClass(this.sessionStoreClz)) {
|
|
19
|
+
this.sessionStore = new this.sessionStoreClz(this.sessionStoreOptions);
|
|
20
|
+
}
|
|
21
|
+
else if (typeof this.sessionStoreClz === 'function') {
|
|
22
|
+
// 因为 session 扩展的规范是传入 express-session 对象,所以这里需要传入 session
|
|
23
|
+
this.sessionStore = new (this.sessionStoreClz(session))(this.sessionStoreOptions);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
this.sessionStore = this.sessionStoreClz;
|
|
27
|
+
}
|
|
19
28
|
}
|
|
20
29
|
return this.sessionStore;
|
|
21
30
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/express-session",
|
|
3
3
|
"description": "midway session component for express",
|
|
4
|
-
"version": "3.15.
|
|
4
|
+
"version": "3.15.11",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"type": "git",
|
|
42
42
|
"url": "https://github.com/midwayjs/midway.git"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "5bf318ca3f6d27e46db173fe4af3a859a40a6c88"
|
|
45
45
|
}
|