diff --git a/Cargo.lock b/Cargo.lock index 83c0edf..451d01e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -147,6 +147,7 @@ checksum = "d09dbe0e490df5da9d69b36dca48a76635288a82f92eca90024883a56202026d" dependencies = [ "async-trait", "axum-core", + "axum-macros", "bytes", "futures-util", "http", @@ -194,6 +195,18 @@ dependencies = [ "tracing", ] +[[package]] +name = "axum-macros" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a2edad600410b905404c594e2523549f1bcd4bded1e252c8f74524ccce0b867" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "axum-server" version = "0.6.0" diff --git a/Cargo.toml b/Cargo.toml index 0c9859b..1d2cc56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,23 +9,23 @@ repositoty = "https://github.com/RGBCube/rgbcube.github.io" edition = "2021" [dependencies] -anyhow = "1.0.77" -axum = "0.7.3" -axum-server = { version = "0.6.0", features = [ "tls-rustls" ] } -bytes = "1.5.0" -cargo_toml = "0.17.2" -chrono = "0.4.31" -clap = { version = "4.4.12", features = [ "derive" ] } -embed = { git = "https://github.com/RGBCube/embed-rs" } -env_logger = "0.10.1" -log = { version = "0.4.20", features = [ "serde" ] } -maud = { git = "https://github.com/lambda-fairy/maud", features = [ "axum" ] } -mime_guess = "2.0.4" -minify-js = "0.6.0" -pulldown-cmark = "0.9.3" -tokio = { version = "1.35.1", features = [ "full" ] } -tower = "0.4.13" -tower-http = { version = "0.5.0", features = [ "trace" ] } +anyhow = "1.0.77" +axum = { version = "0.7.3", features = [ "macros" ] } +axum-server = { version = "0.6.0", features = [ "tls-rustls" ] } +bytes = "1.5.0" +cargo_toml = "0.17.2" +chrono = "0.4.31" +clap = { version = "4.4.12", features = [ "derive" ] } +embed = { git = "https://github.com/RGBCube/embed-rs" } +env_logger = "0.10.1" +log = { version = "0.4.20", features = [ "serde" ] } +maud = { git = "https://github.com/lambda-fairy/maud", features = [ "axum" ] } +mime_guess = "2.0.4" +minify-js = "0.6.0" +pulldown-cmark = "0.9.3" +tokio = { version = "1.35.1", features = [ "full" ] } +tower = "0.4.13" +tower-http = { version = "0.5.0", features = [ "trace" ] } [patch.crates-io] proc-macro2 = { git = "https://github.com/RGBCube/proc-macro2" } diff --git a/src/errors/internal_server_error.rs b/src/errors/internal_server_error.rs index c9298ce..1df7462 100644 --- a/src/errors/internal_server_error.rs +++ b/src/errors/internal_server_error.rs @@ -1,8 +1,8 @@ use std::array; -use actix_web::{ - dev::ServiceResponse, - middleware::ErrorHandlerResponse, +use axum::{ + http::StatusCode, + BoxError, }; use maud::html; @@ -11,12 +11,9 @@ use crate::{ page::cube, }; -pub fn handler( - response: ServiceResponse, -) -> actix_web::Result> { - let (request, response) = response.into_parts(); - - let response = response.set_body( +pub async fn handler(_: BoxError) -> (StatusCode, String) { + ( + StatusCode::INTERNAL_SERVER_ERROR, cube::create( Some("Error"), asset::Css::Shared("cube-grid.css"), @@ -32,11 +29,5 @@ pub fn handler( }), ) .into_string(), - ); - - Ok(ErrorHandlerResponse::Response( - ServiceResponse::new(request, response) - .map_into_boxed_body() - .map_into_right_body(), - )) + ) } diff --git a/src/errors/mod.rs b/src/errors/mod.rs index 55d5eae..1a779e8 100644 --- a/src/errors/mod.rs +++ b/src/errors/mod.rs @@ -1,11 +1,15 @@ -use axum::Router; +use axum::{ + // error_handling::HandleErrorLayer, + Router, +}; +// use tower::ServiceBuilder; -mod internal_server_error; +// mod internal_server_error; mod not_found; -pub fn handler() -> ErrorHandlers { - Router::new().fallback(not_found::handler).handler( - StatusCode::INTERNAL_SERVER_ERROR, - internal_server_error::handler, - ) +pub fn router() -> Router { + Router::new().fallback(not_found::handler) + // TODO + // .layer(ServiceBuilder::new(). + // layer(HandleErrorLayer::new(internal_server_error::handler))) } diff --git a/src/errors/not_found.rs b/src/errors/not_found.rs index e04d480..9ccf9d1 100644 --- a/src/errors/not_found.rs +++ b/src/errors/not_found.rs @@ -10,7 +10,7 @@ use crate::{ page::cube, }; -pub fn handler() -> Markup { +pub async fn handler() -> Markup { cube::create( Some("404"), asset::Css::Shared("cube-grid.css"),