diff --git a/Cargo.toml b/Cargo.toml index 48b3903..b43df50 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,12 +11,12 @@ anyhow = "1.0" askama = { git = "https://github.com/djc/askama.git" } askama_axum = { git = "https://github.com/djc/askama.git", package = "askama_axum" } axum = { version = "0.6", default-features = false, features = ["http1", "form", "tokio", "macros"] } -axum-extra = { version = "0.4", features = ["spa"] } captcha = { version = "0.0.9", default-features = false } lettre = { version = "0.10", default-features = false, features = ["smtp-transport", "hostname", "rustls-tls", "pool", "builder"] } serde = { version = "1.0", features = ["derive"] } serde_yaml = "0.9" tokio = { version = "1.25", default-features = false, features = ["macros", "rt"] } +tower-http = { version = "0.3", features = ["fs"] } tracing = "0.1" tracing-appender = "0.2" tracing-subscriber = "0.3" diff --git a/src/main.rs b/src/main.rs index 14a7bd1..173abee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,12 +9,18 @@ mod states; mod templates; use anyhow::Result; -use axum::routing::get; -use axum::{Router, Server}; -use axum_extra::routing::SpaRouter; -use std::net::{IpAddr, Ipv4Addr, SocketAddr}; -use std::process; -use std::sync::Arc; +use axum::{ + http::StatusCode, + routing::{get, get_service, Router}, + Server, +}; +use std::{ + future::ready, + net::{IpAddr, Ipv4Addr, SocketAddr}, + process, + sync::Arc, +}; +use tower_http::services::ServeDir; use tracing::info; async fn init() -> Result<()> { @@ -41,13 +47,15 @@ async fn init() -> Result<()> { captcha_solutions, }; + let static_service = + get_service(ServeDir::new("static")).handle_error(|_| ready(StatusCode::NOT_FOUND)); + let routes = Router::new() .route("/", get(routes::index).post(routes::submit)) - .with_state(app_state); + .with_state(app_state) + .nest_service("/static", static_service); - let spa = SpaRouter::new(&format!("{}/static", &path_prefix), "static"); - - let app = Router::new().nest(&path_prefix, routes).merge(spa); + let app = Router::new().nest(&path_prefix, routes); info!("Starting server"); Server::bind(&socket_address)