Use ServeDir
This commit is contained in:
parent
99372acf7d
commit
5acfa4556f
2 changed files with 19 additions and 11 deletions
|
@ -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"
|
||||
|
|
28
src/main.rs
28
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)
|
||||
|
|
Loading…
Reference in a new issue