From 5444875e716720c4e8d3f7a1de6cf332b07d1beb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ci=C4=99=C5=BCarkiewicz?= Date: Fri, 26 Jul 2024 14:01:51 -0700 Subject: [PATCH] http: Display simple info page on / --- radicle-httpd/src/api/v1.rs | 5 +++++ radicle-httpd/src/lib.rs | 42 +++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/radicle-httpd/src/api/v1.rs b/radicle-httpd/src/api/v1.rs index 0c0090fa8..66156e394 100644 --- a/radicle-httpd/src/api/v1.rs +++ b/radicle-httpd/src/api/v1.rs @@ -45,6 +45,11 @@ async fn root_handler(State(ctx): State) -> impl IntoResponse { "rel": "node", "type": "GET" }, + { + "href": "/nodes/:nid", + "rel": "node", + "type": "GET" + }, { "href": "/delegates/:did/projects", "rel": "projects", diff --git a/radicle-httpd/src/lib.rs b/radicle-httpd/src/lib.rs index e6268e104..8db83d54f 100644 --- a/radicle-httpd/src/lib.rs +++ b/radicle-httpd/src/lib.rs @@ -14,8 +14,9 @@ use std::time::Duration; use anyhow::Context as _; use axum::body::{Body, HttpBody}; use axum::http::{Request, Response}; -use axum::middleware; -use axum::Router; +use axum::response::IntoResponse; +use axum::routing::get; +use axum::{middleware, Json, Router}; use tokio::net::TcpListener; use tower_http::trace::TraceLayer; use tracing::Span; @@ -115,6 +116,7 @@ fn router(options: Options, profile: Profile) -> anyhow::Result { let raw_router = raw::router(profile); let app = Router::new() + .route("/", get(root_index_handler)) .merge(git_router) .nest("/api", api_router) .nest("/raw", raw_router); @@ -122,6 +124,42 @@ fn router(options: Options, profile: Profile) -> anyhow::Result { Ok(app) } +async fn root_index_handler() -> impl IntoResponse { + let response = serde_json::json!({ + "welcome": "Welcome to the radicle-httpd JSON API, this service doesn't serve the Radicle Explorer web client.", + "path": "/", + "links": [ + { + "href": "/api", + "rel": "api", + "type": "GET" + }, + { + "href": "/raw/:rid/:sha/*path", + "rel": "file_by_commit", + "type": "GET" + }, + { + "href": "/raw/:rid/head/*path", + "rel": "file_by_canonical_head", + "type": "GET" + }, + { + "href": "/raw/:rid/blobs/:oid", + "rel": "file_by_oid", + "type": "GET" + }, + { + "href": "/:project/*request", + "rel": "git", + "type": "GET" + } + ] + }); + + Json(response) +} + pub mod logger { use tracing::dispatcher::Dispatch;