Session component for @midwayjs/express
$ npm i @midwayjs/express-session --save
$ npm i @types/express-session --save-dev
@midwayjs/express has enabled this component by default.
We use cookie-session to keep session by default and use express-session when set custom session store.
You can configure session in your config.*.ts
.
default value.
export const session = {
secret: undefined, // must be set in application
name: 'MW_SESS',
cookie: {
maxAge: 24 * 3600 * 1000, // ms
httpOnly: true,
// sameSite: null,
},
};
You can set 'session.cookie' for cookie-session config.
You can use compatible session store here.
Let's give an example for memorystore.
import { Configuration, Inject } from '@midwayjs/decorator';
import * as session from '@midwayjs/express-session';
import MemoryStore = require('memorystore');
@Configuration({
imports: [
express,
session,
],
//...
})
export class AutoConfiguration {
@Inject()
sessionStoreManager: session.SessionStoreManager;
async onReady() {
this.sessionStoreManager.setSessionStore(MemoryStore, {
checkPeriod: 86400000 // prune expired entries every 24h
});
}
}
Please open an issue here.
MIT