feat: serve openapi.json at /openapi.json endpoint

This commit is contained in:
NetworkCats
2026-03-04 05:02:19 +08:00
parent 6ecb925971
commit ea291f3d30
2 changed files with 11 additions and 1 deletions
+9
View File
@@ -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<AppState>) -> Response {
let body = format!(
"User-agent: *\n\
@@ -344,6 +352,7 @@ pub async fn robots_txt(State(state): State<AppState>) -> Response {
Disallow: /hosting\n\
Disallow: /tor\n\
Disallow: /health\n\
Disallow: /openapi.json\n\
\n\
Sitemap: https://{}/sitemap.xml\n",
state.site_domain
+2 -1
View File
@@ -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))