@@ -76,32 +76,38 @@ app.use(cookieParser());
76
76
77
77
mongoose . set ( 'strictQuery' , true ) ;
78
78
79
- const clientPromise = mongoose
80
- . connect ( mongoConnectionString , {
81
- useNewUrlParser : true ,
82
- useUnifiedTopology : true ,
83
- serverSelectionTimeoutMS : 30000 , // 30 seconds timeout
84
- socketTimeoutMS : 45000 // 45 seconds timeout
85
- } )
86
- . then ( ( m ) => m . connection . getClient ( ) ) ;
79
+ async function initializeSession ( ) {
80
+ try {
81
+ const mongooseConnection = await mongoose . connect ( mongoConnectionString , {
82
+ useNewUrlParser : true ,
83
+ useUnifiedTopology : true ,
84
+ serverSelectionTimeoutMS : 30000 , // 30 seconds timeout
85
+ socketTimeoutMS : 45000 // 45 seconds timeout
86
+ } ) ;
87
+
88
+ app . use (
89
+ session ( {
90
+ resave : true ,
91
+ saveUninitialized : false ,
92
+ secret : process . env . SESSION_SECRET ,
93
+ proxy : true ,
94
+ name : 'sessionId' ,
95
+ cookie : {
96
+ httpOnly : true ,
97
+ secure : false
98
+ } ,
99
+ store : new MongoStore ( {
100
+ mongooseConnection : mongooseConnection . connection ,
101
+ autoReconnect : true
102
+ } )
103
+ } )
104
+ ) ;
105
+ } catch ( error ) {
106
+ console . error ( 'Error connecting to the database:' , error ) ;
107
+ }
108
+ }
87
109
88
- app . use (
89
- session ( {
90
- resave : true ,
91
- saveUninitialized : false ,
92
- secret : process . env . SESSION_SECRET ,
93
- proxy : true ,
94
- name : 'sessionId' ,
95
- cookie : {
96
- httpOnly : true ,
97
- secure : false
98
- } ,
99
- store : new MongoStore ( {
100
- clientPromise,
101
- autoReconnect : true
102
- } )
103
- } )
104
- ) ;
110
+ initializeSession ( ) ;
105
111
106
112
app . use ( '/api/v1' , requestsOfTypeJSON ( ) , api ) ;
107
113
// This is a temporary way to test access via Personal Access Tokens
0 commit comments