1717// ----------------------
1818// These are internal modules for handling the proxy logic, caching layers,
1919// configuration loading, and in-memory eviction based on memory pressure.
20+ mod admin;
2021mod config;
2122mod eviction;
2223mod memory;
2324mod proxy;
2425mod rules;
2526mod storage;
26- mod admin;
2727
2828// ----------------------
2929// External dependencies
3030// ----------------------
31- use axum:: { Router , routing:: get , routing:: delete } ; // Axum: Web framework for routing and request handling
31+ use axum:: { Router , routing:: delete , routing:: get } ; // Axum: Web framework for routing and request handling
3232use hyper:: Server ; // Hyper: High-performance HTTP server
3333use std:: { net:: SocketAddr , process:: exit} ; // Network + system utilities
3434
@@ -38,6 +38,7 @@ use tracing_subscriber::EnvFilter; // Log filtering via LOG_LEVEL
3838
3939use crate :: admin:: clean:: invalidate_handler;
4040use crate :: admin:: status_memory:: get_memory_cache_status;
41+ use crate :: admin:: ui:: { embedded_ui_handler, embedded_ui_index} ;
4142// ----------------------
4243// Internal dependencies
4344// ----------------------
@@ -46,6 +47,9 @@ use crate::eviction::start_background_eviction_task; // Memory pressure eviction
4647use crate :: storage:: { azure, gcs, s3} ; // Persistent storage backends
4748use metrics_exporter_prometheus:: PrometheusBuilder ;
4849
50+ use hyper:: http:: { HeaderValue , Method , header} ;
51+ use tower_http:: cors:: CorsLayer ;
52+
4953/// ----------------------------
5054/// CLI ARGUMENT STRUCTURE
5155/// ----------------------------
@@ -191,12 +195,21 @@ async fn main() {
191195 // 7. Define Axum router with a single wildcard route
192196 // All incoming GET requests will be handled by the proxy logic.
193197 // ------------------------------------------------------
198+ let cors = CorsLayer :: new ( )
199+ . allow_origin ( "http://localhost:4321" . parse :: < HeaderValue > ( ) . unwrap ( ) ) // o use HeaderValue::from_static(...)
200+ . allow_methods ( [ Method :: GET , Method :: POST , Method :: DELETE ] )
201+ . allow_headers ( [ header:: CONTENT_TYPE ] ) ;
202+
194203 let app = Router :: new ( )
204+ . route ( "/cb-admin/api/cache" , delete ( invalidate_handler) )
205+ . route ( "/cb-admin/api/status" , get ( get_memory_cache_status) )
206+ . route ( "/cb-admin" , get ( embedded_ui_index) )
207+ . route ( "/cb-admin/" , get ( embedded_ui_index) )
208+ . route ( "/cb-admin/*path" , get ( embedded_ui_handler) )
195209 . route ( "/metrics" , get ( move || async move { handle. render ( ) } ) )
196- . route ( "/" , get ( proxy:: proxy_handler) )
210+ . route ( "/" , get ( proxy:: proxy_handler) )
197211 . route ( "/*path" , get ( proxy:: proxy_handler) )
198- . route ( "/admin/cache" , delete ( invalidate_handler) )
199- . route ( "/admin/status-memory" , get ( get_memory_cache_status) ) ;
212+ . layer ( cors) ;
200213
201214 // ------------------------------------------------------
202215 // 8. Bind the server to all interfaces on port 3000
0 commit comments