@@ -8,20 +8,32 @@ import session from 'express-session';
88import cookieParser from 'cookie-parser' ;
99import bodyParser from 'body-parser' ;
1010
11- config ( ) ;
11+ config ( ) ; // load .env variables
1212
13+ const app : Express = express ( ) ;
1314const port : number = Number ( process . env . PORT ) || 3000 ;
1415
15- const app : Express = express ( ) ;
1616//Set the payload limit size to 1mb when save a large database data which is TableData in featureTab.
1717app . use ( bodyParser . json ( { limit : '1mb' } ) ) ;
1818app . use ( bodyParser . urlencoded ( { limit : '1mb' , extended : true } ) ) ;
1919
20+ // Core express middlewares
2021app . use ( express . json ( ) ) ;
2122app . use ( express . urlencoded ( { extended : true } ) ) ;
23+
24+ // Cookies and CORS
2225app . use ( cookieParser ( ) ) ;
2326app . use ( cors ( ) ) ;
27+
28+ // Serve static files from 'dist'
2429app . 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+
2537app . use (
2638 session ( {
2739 secret : process . env . SESSION_SECRET as string ,
@@ -31,15 +43,16 @@ app.use(
3143 secure : false ,
3244 httpOnly : true ,
3345 path : '/' ,
34- sameSite : true ,
46+ sameSite : 'lax' ,
3547 maxAge : 24 * 60 * 60 * 1000 ,
3648 } ,
3749 } )
3850) ;
3951
52+ // Start the server
4053app . 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
4356} ) ;
4457
4558export default app ;
0 commit comments