mirror of
https://github.com/tokio-rs/axum.git
synced 2024-11-22 15:17:18 +01:00
24 lines
720 B
Rust
24 lines
720 B
Rust
use http::StatusCode;
|
|
use std::net::SocketAddr;
|
|
use tower_http::{services::ServeDir, trace::TraceLayer};
|
|
use tower_web::{prelude::*, service::ServiceExt};
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
tracing_subscriber::fmt::init();
|
|
|
|
let app = tower_web::routing::nest(
|
|
"/static",
|
|
tower_web::service::get(ServeDir::new(".").handle_error(|error: std::io::Error| {
|
|
(
|
|
StatusCode::INTERNAL_SERVER_ERROR,
|
|
format!("Unhandled interal error: {}", error),
|
|
)
|
|
})),
|
|
)
|
|
.layer(TraceLayer::new_for_http());
|
|
|
|
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
|
tracing::debug!("listening on {}", addr);
|
|
app.serve(&addr).await.unwrap();
|
|
}
|