@@ -35,7 +35,11 @@ import { logger } from './lib/logger.js';
3535
3636const CORS_ORIGIN = process . env . CORS_ORIGIN || 'http://localhost:6373' ;
3737const corsOrigin = CORS_ORIGIN . includes ( ',' )
38- ? CORS_ORIGIN . split ( ',' ) . map ( o => o . trim ( ) )
38+ ? CORS_ORIGIN . split ( ',' ) . map ( o => {
39+ const trimmed = o . trim ( ) ;
40+ new URL ( trimmed ) ; // throws on invalid origin
41+ return trimmed ;
42+ } )
3943 : CORS_ORIGIN ;
4044
4145const app = express ( ) ;
@@ -114,8 +118,18 @@ if (existsSync(clientDist)) {
114118// Error handling
115119app . use ( errorHandler ) ;
116120
117- httpServer . listen ( PORT , '0.0.0.0' , ( ) => {
118- logger . start ( 'server' , `Running on http://localhost:${ PORT } ` ) ;
121+ const HOST = process . env . HOST || 'localhost' ;
122+
123+ const shutdown = ( ) => {
124+ logger . warn ( 'server' , 'Shutting down gracefully...' ) ;
125+ httpServer . close ( ( ) => process . exit ( 0 ) ) ;
126+ setTimeout ( ( ) => process . exit ( 1 ) , 5000 ) ;
127+ } ;
128+ process . on ( 'SIGTERM' , shutdown ) ;
129+ process . on ( 'SIGINT' , shutdown ) ;
130+
131+ httpServer . listen ( PORT , HOST , ( ) => {
132+ logger . start ( 'server' , `Running on http://${ HOST } :${ PORT } ` ) ;
119133
120134 // Auto-connect to browser if enabled and browser is running
121135 browserService . autoConnectIfEnabled ( ) ;
0 commit comments