fix: update code to work with newer versions
							parent
							
								
									63d0b1fc86
								
							
						
					
					
						commit
						5fa892f5a3
					
				
							
								
								
									
										31
									
								
								src/main.rs
								
								
								
								
							
							
						
						
									
										31
									
								
								src/main.rs
								
								
								
								
							| 
						 | 
					@ -2,13 +2,14 @@ use std::{future::ready, net::SocketAddr};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use axum::{
 | 
					use axum::{
 | 
				
			||||||
    extract::Extension,
 | 
					    extract::Extension,
 | 
				
			||||||
    http::StatusCode,
 | 
					 | 
				
			||||||
    middleware,
 | 
					    middleware,
 | 
				
			||||||
    response::Redirect,
 | 
					    response::Redirect,
 | 
				
			||||||
    routing::{any, get, get_service},
 | 
					    routing::{any, get},
 | 
				
			||||||
    Router,
 | 
					    Router,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use tower_http::{auth::RequireAuthorizationLayer, services::ServeDir, trace::TraceLayer};
 | 
					use tower_http::{
 | 
				
			||||||
 | 
					    services::ServeDir, trace::TraceLayer, validate_request::ValidateRequestHeaderLayer,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
 | 
					use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mod api;
 | 
					mod api;
 | 
				
			||||||
| 
						 | 
					@ -46,7 +47,7 @@ async fn main() {
 | 
				
			||||||
        // Routes under /api path
 | 
					        // Routes under /api path
 | 
				
			||||||
        .nest(
 | 
					        .nest(
 | 
				
			||||||
            "/api",
 | 
					            "/api",
 | 
				
			||||||
            api::router().layer(RequireAuthorizationLayer::bearer(&api_key)),
 | 
					            api::router().layer(ValidateRequestHeaderLayer::bearer(&api_key)),
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        .route("/metrics", get(move || ready(recorder_handle.render())));
 | 
					        .route("/metrics", get(move || ready(recorder_handle.render())));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -61,17 +62,7 @@ async fn main() {
 | 
				
			||||||
    for (path, dir) in sites {
 | 
					    for (path, dir) in sites {
 | 
				
			||||||
        let full_path = format!("{}/{}", static_dir, dir);
 | 
					        let full_path = format!("{}/{}", static_dir, dir);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        app = app.nest(
 | 
					        app = app.nest_service(path, ServeDir::new(full_path));
 | 
				
			||||||
            path,
 | 
					 | 
				
			||||||
            get_service(ServeDir::new(full_path)).handle_error(
 | 
					 | 
				
			||||||
                |error: std::io::Error| async move {
 | 
					 | 
				
			||||||
                    (
 | 
					 | 
				
			||||||
                        StatusCode::INTERNAL_SERVER_ERROR,
 | 
					 | 
				
			||||||
                        format!("Unhandled internal error: {}", error),
 | 
					 | 
				
			||||||
                    )
 | 
					 | 
				
			||||||
                },
 | 
					 | 
				
			||||||
            ),
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Define some redirects
 | 
					    // Define some redirects
 | 
				
			||||||
| 
						 | 
					@ -90,18 +81,10 @@ async fn main() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    app = app
 | 
					    app = app
 | 
				
			||||||
        // The fallback option is to serve the actual static files
 | 
					        // The fallback option is to serve the actual static files
 | 
				
			||||||
        .fallback(
 | 
					        .fallback_service(ServeDir::new(format!(
 | 
				
			||||||
            get_service(ServeDir::new(format!(
 | 
					 | 
				
			||||||
            "{}/{}",
 | 
					            "{}/{}",
 | 
				
			||||||
            static_dir, DEFAULT_STATIC_SITE
 | 
					            static_dir, DEFAULT_STATIC_SITE
 | 
				
			||||||
        )))
 | 
					        )))
 | 
				
			||||||
            .handle_error(|error: std::io::Error| async move {
 | 
					 | 
				
			||||||
                (
 | 
					 | 
				
			||||||
                    StatusCode::INTERNAL_SERVER_ERROR,
 | 
					 | 
				
			||||||
                    format!("Unhandled internal error: {}", error),
 | 
					 | 
				
			||||||
                )
 | 
					 | 
				
			||||||
            }),
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
        .layer(middleware::from_fn(metrics::track_metrics))
 | 
					        .layer(middleware::from_fn(metrics::track_metrics))
 | 
				
			||||||
        .layer(Extension(data_dir))
 | 
					        .layer(Extension(data_dir))
 | 
				
			||||||
        .layer(TraceLayer::new_for_http());
 | 
					        .layer(TraceLayer::new_for_http());
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue