diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 40 |
1 files changed, 37 insertions, 3 deletions
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<E> From<E> for AppError +where + E: Into<anyhow::Error>, +{ + 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<impl IntoResponse, AppError> { + Ok(html!({})) } |
