mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-26 01:40:36 +00:00
feat: add redoc UI support
This commit is contained in:
@@ -11,6 +11,7 @@ use aide::axum::routing as apirouting;
|
||||
use aide::axum::{ApiRouter, IntoApiResponse};
|
||||
use aide::openapi::{Info, OpenApi};
|
||||
use async_trait::async_trait;
|
||||
use axum::response::Html;
|
||||
use axum::Extension;
|
||||
use axum::{error_handling::HandleErrorLayer, response::Json, routing, BoxError, Router};
|
||||
use common_query::Output;
|
||||
@@ -204,10 +205,14 @@ async fn shutdown_signal() {
|
||||
.expect("failed to install CTRL+C signal handler");
|
||||
}
|
||||
|
||||
async fn serve_api(Extension(api): Extension<OpenApi>) -> impl IntoApiResponse {
|
||||
async fn serve_api(Extension(api): Extension<Arc<OpenApi>>) -> impl IntoApiResponse {
|
||||
Json(api)
|
||||
}
|
||||
|
||||
async fn serve_docs() -> Html<String> {
|
||||
Html(include_str!("http/redoc.html").to_owned())
|
||||
}
|
||||
|
||||
impl HttpServer {
|
||||
pub fn new(sql_handler: SqlQueryHandlerRef) -> Self {
|
||||
Self {
|
||||
@@ -269,6 +274,7 @@ impl HttpServer {
|
||||
.api_route("/scripts", apirouting::post(handler::scripts))
|
||||
.api_route("/run-script", apirouting::post(handler::run_script))
|
||||
.route("/private/api.json", apirouting::get(serve_api))
|
||||
.route("/private/docs", apirouting::get(serve_docs))
|
||||
.finish_api(&mut api)
|
||||
.layer(Extension(Arc::new(api)));
|
||||
|
||||
|
||||
27
src/servers/src/http/redoc.html
Normal file
27
src/servers/src/http/redoc.html
Normal file
@@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Redoc</title>
|
||||
<!-- needed for adaptive design -->
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
|
||||
<!--
|
||||
Redoc doesn't change outer page styles
|
||||
-->
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<redoc spec-url="/v1/private/api.json"></redoc>
|
||||
<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user