@@ -475,22 +475,6 @@ export class ExpressServer {
475475
476476 /**
477477 * Configure and register all middlewares in the optimal order.
478- *
479- * Middleware Order (CRITICAL - don't change without understanding implications):
480- * 1. Basic server configuration (trust proxy, x-powered-by)
481- * 2. Request ID generation (for tracing)
482- * 3. Request context setup (for logging correlation)
483- * 4. Timeout protection (prevents hanging requests)
484- * 5. Response time tracking (for performance monitoring)
485- * 6. Request logging (after ID/context setup)
486- * 7. Custom request hooks
487- * 8. Security middleware (rate limiting, CORS, Helmet)
488- * 9. Response compression
489- * 10. Static file serving
490- * 11. Request parsing (body parsing, cookies)
491- * 12. API documentation (OpenAPI)
492- * 13. Global headers
493- * 14. Custom response hooks
494478 */
495479 protected async setupMiddleware ( ) : Promise < void > {
496480 // Basic middleware should be first
@@ -526,7 +510,6 @@ export class ExpressServer {
526510 ) ;
527511 }
528512
529- // --- 2-6. Request processing and logging setup ---
530513 // Request ID generation - must be first for proper tracing
531514 const requestIdMiddleware = requestId ( {
532515 headerName : this . config . requestId ?. headerName ,
@@ -583,35 +566,6 @@ export class ExpressServer {
583566 this . _app . use ( this . hooks . onRequest ) ;
584567 }
585568
586- // --- 8. Security middleware ---
587- // Rate limiting for DDoS protection and fair usage
588- if ( this . config . rateLimit ?. enable ) {
589- this . _app . use (
590- rateLimit ( {
591- windowMs : this . config . rateLimit . windowMs ?? 15 * 60 * 1000 ,
592- max : this . config . rateLimit . max ?? 100 ,
593- message : this . config . rateLimit . message ?? 'Too many requests, please try again later' ,
594- standardHeaders : this . config . rateLimit . standardHeaders ?? true ,
595- legacyHeaders : this . config . rateLimit . legacyHeaders ?? false
596- } )
597- ) ;
598- }
599-
600- // CORS handling for cross-origin requests
601- if ( this . config . cors ) {
602- this . _app . use ( cors ( this . config . cors === true ? { } : this . config . cors ) ) ;
603- }
604-
605- // Security headers via Helmet (CSP, HSTS, etc.)
606- if ( this . config . helmet ) {
607- if ( typeof this . config . helmet === 'object' ) {
608- this . _app . use ( helmet ( this . config . helmet ) ) ;
609- } else {
610- this . _app . use ( helmet ( ) ) ;
611- }
612- }
613-
614- // --- 9-10. Performance middleware ---
615569 // Response compression for better performance
616570 if ( this . config . compression ) {
617571 if ( typeof this . config . compression === 'object' ) {
@@ -637,7 +591,6 @@ export class ExpressServer {
637591 } ) ;
638592 }
639593
640- // --- 11. Request parsing ---
641594 // Request body parsing with size limits
642595 if ( this . config . bodyParser ) {
643596 if ( this . config . bodyParser . json ) {
@@ -657,7 +610,6 @@ export class ExpressServer {
657610 }
658611 }
659612
660- // --- 12. API Documentation ---
661613 // OpenAPI docs via @scalar /express-api-reference
662614 if ( this . config . openApi ?. enable ) {
663615 try {
@@ -694,7 +646,6 @@ export class ExpressServer {
694646 }
695647 }
696648
697- // --- 13. Global headers ---
698649 // Global headers middleware
699650 if ( this . config . globalHeaders ) {
700651 this . _app . use ( ( _req , res , next ) => {
@@ -706,7 +657,6 @@ export class ExpressServer {
706657 } ) ;
707658 }
708659
709- // --- 14. Custom response hooks ---
710660 // Custom response preprocessing hook (apply global prefix if set)
711661 if ( this . hooks . onResponse ) {
712662 if ( this . globalPrefix ) {
0 commit comments