From d1dc5d0d652030847e8ee593bf4007e6ffefaf1a Mon Sep 17 00:00:00 2001 From: WriterV2 Date: Sat, 10 Aug 2024 19:23:25 +0200 Subject: Feat: Add empty home route --- src/main.rs | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 37f1399..7936364 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,39 @@ -use anyhow::Result; +use axum::http::StatusCode; +use axum::response::IntoResponse; +use axum::routing::get; +use axum::Router; +use maud::html; -fn main() -> Result<()> { - Ok(()) +struct AppError(anyhow::Error); + +impl IntoResponse for AppError { + fn into_response(self) -> axum::response::Response { + ( + StatusCode::INTERNAL_SERVER_ERROR, + format!("Something went wrong: {}", self.0), + ) + .into_response() + } +} + +impl From for AppError +where + E: Into, +{ + fn from(err: E) -> Self { + Self(err.into()) + } +} + +#[tokio::main] +async fn main() { + let app = Router::new().route("/", get(home)); + let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); + axum::serve(listener, app.into_make_service()) + .await + .unwrap(); +} + +async fn home() -> Result { + Ok(html!({})) } -- cgit v1.2.3