import DI, {DDNames} from "@gongt/ts-stl-library/DI"; import * as expressSession from "express-session"; const createMongoDBStore = require('connect-mongodb-session'); export function initMongodbSession(mongoUrl: string, table: string = "express-session") { const MongoStore = createMongoDBStore(expressSession); const cookieSignedKey = DI.get(DDNames.cookieSignKey); const store = new MongoStore({ uri: mongoUrl, collection: table, }); store.on('error', function (error) { throw error; }); DI.set(DDNames.sessionHandler, expressSession({ secret: cookieSignedKey, resave: false, saveUninitialized: false, store: store, })); }