11package org .juv25d ;
22
3- import org .juv25d .filter .IpFilter ;
4- import org .juv25d .filter .LoggingFilter ;
5- import org .juv25d .filter .RateLimitingFilter ;
3+ import org .juv25d .filter .*;
64import org .juv25d .logging .ServerLogging ;
75import org .juv25d .http .HttpParser ;
6+ import org .juv25d .plugin .HealthCheckPlugin ;
7+ import org .juv25d .plugin .MetricPlugin ;
88import org .juv25d .plugin .NotFoundPlugin ; // New import
99import org .juv25d .plugin .StaticFilesPlugin ;
10- import org .juv25d .router .SimpleRouter ; // New import
10+ import org .juv25d .router .SimpleRouter ;
1111import org .juv25d .util .ConfigLoader ;
12- import org .juv25d .filter .RedirectFilter ;
13- import org .juv25d .filter .RedirectRule ;
12+
1413import java .util .List ;
1514
1615import java .util .Set ;
@@ -21,40 +20,34 @@ public static void main(String[] args) {
2120 ConfigLoader config = ConfigLoader .getInstance ();
2221 Logger logger = ServerLogging .getLogger ();
2322 HttpParser httpParser = new HttpParser ();
24-
2523 Pipeline pipeline = new Pipeline ();
26- // Configure redirect rules
24+
25+ pipeline .addGlobalFilter (new SecurityHeadersFilter (), 0 );
26+
27+ pipeline .addGlobalFilter (new LoggingFilter (), 1 );
28+
29+ pipeline .addGlobalFilter (new IpFilter (Set .of (), Set .of ()), 2 );
30+
31+ if (config .isRateLimitingEnabled ()) {pipeline .addGlobalFilter (new RateLimitingFilter (
32+ config .getRequestsPerMinute (), config .getBurstCapacity ()), 3 );}
33+
2734 List <RedirectRule > redirectRules = List .of (
2835 new RedirectRule ("/old-page" , "/new-page" , 301 ),
2936 new RedirectRule ("/temp" , "https://example.com/temporary" , 302 ),
3037 new RedirectRule ("/docs/*" , "/documentation/" , 301 )
3138 );
32- pipeline .addGlobalFilter (new RedirectFilter (redirectRules ), 0 );
33-
3439
35- // IP filter is enabled but configured with open access during development
36- // White/blacklist can be tightened when specific IP restrictions are decided
37- pipeline .addGlobalFilter (new IpFilter (
38- Set .of (),
39- Set .of ()
40- ), 0 );
40+ pipeline .addGlobalFilter (new RedirectFilter (redirectRules ), 4 );
4141
42- pipeline .addGlobalFilter (new LoggingFilter (), 0 );
4342
44- if (config .isRateLimitingEnabled ()) {
45- pipeline .addGlobalFilter (new RateLimitingFilter (
46- config .getRequestsPerMinute (),
47- config .getBurstCapacity ()
48- ), 0 );
49- }
50-
51- // Initialize and configure SimpleRouter
5243 SimpleRouter router = new SimpleRouter ();
44+ router .registerPlugin ("/metric" , new MetricPlugin ()); //Register MetricPlugin for a specified path
45+ router .registerPlugin ("/health" , new HealthCheckPlugin ()); //Register HealthCheckPlugin for a specified path
5346 router .registerPlugin ("/" , new StaticFilesPlugin ()); // Register StaticFilesPlugin for the root path
5447 router .registerPlugin ("/*" , new StaticFilesPlugin ()); // Register StaticFilesPlugin for all paths
5548 router .registerPlugin ("/notfound" , new NotFoundPlugin ()); // Example: Register NotFoundPlugin for a specific path
5649
57- pipeline .setRouter (router ); // Set the router in the pipeline
50+ pipeline .setRouter (router );
5851
5952 DefaultConnectionHandlerFactory handlerFactory =
6053 new DefaultConnectionHandlerFactory (httpParser , logger , pipeline );
@@ -65,7 +58,6 @@ public static void main(String[] args) {
6558 handlerFactory ,
6659 pipeline
6760 );
68-
6961 server .start ();
7062 }
7163}
0 commit comments