Radish alpha
r
rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5
Radicle web interface
Radicle
Git
http: Display simple info page on /
Dawid Ciężarkiewicz committed 1 year ago
commit 5444875e716720c4e8d3f7a1de6cf332b07d1beb
parent 06fa429
2 files changed +45 -2
modified radicle-httpd/src/api/v1.rs
@@ -46,6 +46,11 @@ async fn root_handler(State(ctx): State<Context>) -> impl IntoResponse {
                "type": "GET"
            },
            {
+
                "href": "/nodes/:nid",
+
                "rel": "node",
+
                "type": "GET"
+
            },
+
            {
                "href": "/delegates/:did/projects",
                "rel": "projects",
                "type": "GET"
modified 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<Router> {
    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<Router> {
    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;