File tree 3 files changed +70
-6
lines changed
3 files changed +70
-6
lines changed Original file line number Diff line number Diff line change 52
52
"bcrypt" : " ^5.1.0" ,
53
53
"class-transformer" : " ^0.5.1" ,
54
54
"class-validator" : " ^0.14.0" ,
55
+ "connect-mongo" : " ^5.1.0" ,
55
56
"dotenv" : " ^16.0.3" ,
56
57
"express-session" : " ^1.17.3" ,
57
58
"handlebars" : " ^4.7.7" ,
93
94
"@types/bcrypt" : " ^5.0.0" ,
94
95
"@types/chai" : " ^5.0.0" ,
95
96
"@types/express" : " ^5.0.0" ,
96
- "@types/express-session" : " ^1.17.4 " ,
97
+ "@types/express-session" : " ^1.18.1 " ,
97
98
"@types/jest" : " ^27.0.2" ,
98
99
"@types/js-yaml" : " ^4.0.9" ,
99
100
"@types/jsonpath-plus" : " ^5.0.5" ,
Original file line number Diff line number Diff line change 1
1
import session from "express-session" ;
2
+ import MongoStore from "connect-mongo" ;
2
3
import { NestFactory } from "@nestjs/core" ;
3
4
import {
4
5
DocumentBuilder ,
@@ -95,21 +96,28 @@ async function bootstrap() {
95
96
const expressSessionSecret = configService . get < string > (
96
97
"expressSessionSecret" ,
97
98
) ;
99
+ const mongoUrl = configService . get < string > ( "mongodbUri" ) ;
100
+
98
101
if ( expressSessionSecret ) {
99
102
app . use (
100
103
session ( {
101
104
secret : expressSessionSecret ,
102
105
resave : false ,
103
106
saveUninitialized : true ,
107
+ store : MongoStore . create ( {
108
+ mongoUrl, // MongoDB connection string
109
+ collectionName : "sessions" , // Collection name for storing sessions
110
+ ttl : 24 * 60 * 60 , // Session TTL (24 hours)
111
+ } ) ,
112
+ cookie : {
113
+ secure : true ,
114
+ } ,
104
115
} ) ,
105
116
) ;
106
117
}
107
118
108
119
const port = configService . get < number > ( "port" ) ?? 3000 ;
109
- Logger . log (
110
- "MongoDB URI : " + configService . get < string > ( "mongodbUri" ) ,
111
- "Main" ,
112
- ) ;
120
+ Logger . log ( "MongoDB URI : " + mongoUrl , "Main" ) ;
113
121
Logger . log ( "Scicat Backend listening on port: " + port , "Main" ) ;
114
122
115
123
await app . listen ( port ) ;
You can’t perform that action at this time.
0 commit comments