Skip to content

Commit

Permalink
express: can give custom express-session
Browse files Browse the repository at this point in the history
  • Loading branch information
sixmen committed Nov 7, 2023
1 parent 3ab2750 commit 49c398a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/express/lib/config.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import express from 'express';
import expressSession from 'express-session';
import log4js from 'log4js';
export interface IExpressConfig {
project_name?: string;
Expand All @@ -21,6 +22,7 @@ export interface IExpressConfig {
*/
secure?: boolean;
same_site?: boolean | 'lax' | 'strict' | 'none';
custom_module?: typeof expressSession;
};
errors?: {
[key: string]: Error;
Expand Down
5 changes: 3 additions & 2 deletions packages/express/lib/create_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ function setupSession(app, config) {
if (!config.session) {
return;
}
const RedisStore = (0, connect_redis_1.default)(express_session_1.default);
const customExpressSession = config.session.custom_module ?? express_session_1.default;
const RedisStore = (0, connect_redis_1.default)(customExpressSession);
const port = config.session.redis?.port ?? 6379;
const host = config.session.redis?.host ?? '127.0.0.1';
const redis_client = new ioredis_1.default({
Expand All @@ -102,7 +103,7 @@ function setupSession(app, config) {
process.exit(0);
}, 1000);
});
const session_middleware = (0, express_session_1.default)({
const session_middleware = customExpressSession({
cookie: {
domain: config.session.domain,
maxAge: config.session.ttl * 1000,
Expand Down
2 changes: 2 additions & 0 deletions packages/express/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import express from 'express';
import expressSession from 'express-session';
import log4js from 'log4js';

export interface IExpressConfig {
Expand All @@ -22,6 +23,7 @@ export interface IExpressConfig {
*/
secure?: boolean;
same_site?: boolean | 'lax' | 'strict' | 'none';
custom_module?: typeof expressSession;
};
errors?: { [key: string]: Error };
routers: { [path: string]: (router: express.Router, app: express.Application) => void };
Expand Down
5 changes: 3 additions & 2 deletions packages/express/src/create_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ function setupSession(app: express.Express, config: IExpressConfig) {
if (!config.session) {
return;
}
const RedisStore = connectRedis(expressSession);
const customExpressSession = config.session.custom_module ?? expressSession;
const RedisStore = connectRedis(customExpressSession);
const port = config.session.redis?.port ?? 6379;
const host = config.session.redis?.host ?? '127.0.0.1';
const redis_client = new Redis({
Expand All @@ -83,7 +84,7 @@ function setupSession(app: express.Express, config: IExpressConfig) {
process.exit(0);
}, 1000);
});
const session_middleware = expressSession({
const session_middleware = customExpressSession({
cookie: {
domain: config.session.domain,
maxAge: config.session.ttl * 1000,
Expand Down

0 comments on commit 49c398a

Please sign in to comment.