@@ -8,20 +8,32 @@ import session from 'express-session';
8
8
import cookieParser from 'cookie-parser' ;
9
9
import bodyParser from 'body-parser' ;
10
10
11
- config ( ) ;
11
+ config ( ) ; // load .env variables
12
12
13
+ const app : Express = express ( ) ;
13
14
const port : number = Number ( process . env . PORT ) || 3000 ;
14
15
15
- const app : Express = express ( ) ;
16
16
//Set the payload limit size to 1mb when save a large database data which is TableData in featureTab.
17
17
app . use ( bodyParser . json ( { limit : '1mb' } ) ) ;
18
18
app . use ( bodyParser . urlencoded ( { limit : '1mb' , extended : true } ) ) ;
19
19
20
+ // Core express middlewares
20
21
app . use ( express . json ( ) ) ;
21
22
app . use ( express . urlencoded ( { extended : true } ) ) ;
23
+
24
+ // Cookies and CORS
22
25
app . use ( cookieParser ( ) ) ;
23
26
app . use ( cors ( ) ) ;
27
+
28
+ // Serve static files from 'dist'
24
29
app . use ( express . static ( path . join ( __dirname , '../dist' ) ) ) ;
30
+
31
+ // Session setup
32
+ if ( ! process . env . SESSION_SECRET ) {
33
+ console . error ( '❌ SESSION_SECRET is not defined in environment variables!' ) ;
34
+ process . exit ( 1 ) ; // Exit early if SESSION_SECRET is missing
35
+ }
36
+
25
37
app . use (
26
38
session ( {
27
39
secret : process . env . SESSION_SECRET as string ,
@@ -31,15 +43,16 @@ app.use(
31
43
secure : false ,
32
44
httpOnly : true ,
33
45
path : '/' ,
34
- sameSite : true ,
46
+ sameSite : 'lax' ,
35
47
maxAge : 24 * 60 * 60 * 1000 ,
36
48
} ,
37
49
} )
38
50
) ;
39
51
52
+ // Start the server
40
53
app . listen ( port , ( ) => {
41
- log . info ( `Securely Running at ${ port } ` ) ;
42
- routes ( app ) ;
54
+ log . info ( `✅ Server running securely at ${ port } ` ) ;
55
+ routes ( app ) ; // register routes AFTER all middlewares
43
56
} ) ;
44
57
45
58
export default app ;
0 commit comments