1use std::sync::Arc;
2
3use axum::{Router, response::IntoResponse, routing::get};
4use http::{StatusCode, Uri};
5use ruma::api::error::ErrorKind;
6use tuwunel_api::router::{state, state::Guard};
7use tuwunel_core::Error;
8use tuwunel_service::Services;
9
10pub(crate) fn build(services: &Arc<Services>) -> (Router, Guard) {
11 let router = Router::<state::State>::new();
12 let (state, guard) = state::create(services.clone());
13 let router = tuwunel_api::router::build(router, &services.server)
14 .route("/", get(it_works))
15 .fallback(not_found)
16 .method_not_allowed_fallback(method_not_allowed)
17 .with_state(state);
18
19 (router, guard)
20}
21
22async fn not_found(_uri: Uri) -> impl IntoResponse {
23 Error::Request(ErrorKind::Unrecognized, "Not Found".into(), StatusCode::NOT_FOUND)
24}
25
26async fn method_not_allowed() -> StatusCode { StatusCode::METHOD_NOT_ALLOWED }
28
29async fn it_works() -> &'static str { "hewwo from tuwunel woof!" }