diff --git a/src/api/ha_registry/mod.rs b/src/api/ha_registry/mod.rs index 57c500a..465e6c3 100644 --- a/src/api/ha_registry/mod.rs +++ b/src/api/ha_registry/mod.rs @@ -3,4 +3,6 @@ // // SPDX-License-Identifier: AGPL-3.0-only -pub mod v1; +pub mod routes; + +mod v1; diff --git a/src/api/ha_registry/routes.rs b/src/api/ha_registry/routes.rs new file mode 100644 index 0000000..3a8c01a --- /dev/null +++ b/src/api/ha_registry/routes.rs @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: 2024 Christina Sørensen +// SPDX-FileContributor: Christina Sørensen +// +// SPDX-License-Identifier: AGPL-3.0-only + +use axum::{extract::Extension, routing::get, Router}; + +use super::v1::routes::get_routes as get_v1_routes; + +pub fn get_routes() -> Router { + Router::new().nest("/v1", get_v1_routes()) +} diff --git a/src/api/routes.rs b/src/api/routes.rs index 71260e8..44acee0 100644 --- a/src/api/routes.rs +++ b/src/api/routes.rs @@ -3,7 +3,7 @@ // // SPDX-License-Identifier: AGPL-3.0-only -use super::ha_registry::v1::routes::get_routes as get_ha_routes; +use super::ha_registry::routes::get_routes as get_ha_routes; use axum::Router; pub fn get_routes() -> Router { diff --git a/src/main.rs b/src/main.rs index fa0649b..91475d8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ #![deny(clippy::unwrap_used)] -use axum::{extract::Extension, response::Redirect, routing::get, Router}; +use axum::{http::StatusCode, extract::Extension, response::{Redirect, IntoResponse}, routing::get, Router}; use tokio::net::TcpListener; extern crate log; @@ -20,6 +20,10 @@ use api::routes::get_routes as get_api_routes; #[allow(unused)] use log::{debug, error, info, trace, warn}; +async fn handler_404() -> impl IntoResponse { + (StatusCode::NOT_FOUND, "404 - not found") +} + #[tokio::main] async fn main() { pretty_env_logger::init(); @@ -42,6 +46,7 @@ async fn main() { get(|| async { Redirect::to("https://github.com/cafkafk/ha-registry") }), ) .merge(get_api_routes()) + .fallback(handler_404) .layer(Extension(config.clone())); let listener = TcpListener::bind(&config.bind_addr())