diff --git a/.woodpecker/.build.yml b/.woodpecker/.build.yml deleted file mode 100644 index 22ea77e..0000000 --- a/.woodpecker/.build.yml +++ /dev/null @@ -1,7 +0,0 @@ -platform: 'linux/amd64' - -pipeline: - lint: - image: 'rustlang/rust:1.69' - commands: - - cargo build diff --git a/Dockerfile b/Dockerfile index 62ecb30..d56f706 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.69-alpine3.16 AS builder +FROM rust:1.64-alpine3.16 AS builder ARG DI_VER=1.2.5 diff --git a/src/main.rs b/src/main.rs index fdb0600..cf75511 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,14 +2,13 @@ use std::{future::ready, net::SocketAddr}; use axum::{ extract::Extension, + http::StatusCode, middleware, response::Redirect, - routing::{any, get}, + routing::{any, get, get_service}, Router, }; -use tower_http::{ - services::ServeDir, trace::TraceLayer, validate_request::ValidateRequestHeaderLayer, -}; +use tower_http::{auth::RequireAuthorizationLayer, services::ServeDir, trace::TraceLayer}; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; mod api; @@ -47,7 +46,7 @@ async fn main() { // Routes under /api path .nest( "/api", - api::router().layer(ValidateRequestHeaderLayer::bearer(&api_key)), + api::router().layer(RequireAuthorizationLayer::bearer(&api_key)), ) .route("/metrics", get(move || ready(recorder_handle.render()))); @@ -62,7 +61,17 @@ async fn main() { for (path, dir) in sites { let full_path = format!("{}/{}", static_dir, dir); - app = app.nest_service(path, ServeDir::new(full_path)); + app = app.nest( + 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 @@ -81,10 +90,18 @@ async fn main() { app = app // The fallback option is to serve the actual static files - .fallback_service(ServeDir::new(format!( - "{}/{}", - static_dir, DEFAULT_STATIC_SITE - ))) + .fallback( + get_service(ServeDir::new(format!( + "{}/{}", + 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(Extension(data_dir)) .layer(TraceLayer::new_for_http());