From ea291f3d30fd8128f841e49592118c5ad0f42be4 Mon Sep 17 00:00:00 2001 From: NetworkCats Date: Wed, 4 Mar 2026 05:02:19 +0800 Subject: [PATCH] feat: serve openapi.json at /openapi.json endpoint --- src/handlers.rs | 9 +++++++++ src/routes.rs | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/handlers.rs b/src/handlers.rs index 29f3d89..054cf35 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -329,6 +329,14 @@ pub async fn tor_handler( Ok(format!("{}\n", proxy.is_tor)) } +pub async fn openapi_json() -> Response { + ( + [(header::CONTENT_TYPE, "application/json; charset=utf-8")], + include_str!("../openapi.json"), + ) + .into_response() +} + pub async fn robots_txt(State(state): State) -> Response { let body = format!( "User-agent: *\n\ @@ -344,6 +352,7 @@ pub async fn robots_txt(State(state): State) -> Response { Disallow: /hosting\n\ Disallow: /tor\n\ Disallow: /health\n\ + Disallow: /openapi.json\n\ \n\ Sitemap: https://{}/sitemap.xml\n", state.site_domain diff --git a/src/routes.rs b/src/routes.rs index 4a4e836..4b78ca6 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -1,6 +1,6 @@ -use axum::Router; use axum::middleware; use axum::routing::get; +use axum::Router; use crate::handlers::{self, AppState}; use crate::middleware::security_headers; @@ -10,6 +10,7 @@ pub fn build_router(state: AppState) -> Router { Router::new() .route("/", get(handlers::root)) .route("/health", get(handlers::health)) + .route("/openapi.json", get(handlers::openapi_json)) .route("/robots.txt", get(handlers::robots_txt)) .route("/sitemap.xml", get(handlers::sitemap_xml)) .route("/json", get(handlers::json_handler))