Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve docs from the server #435

Merged
merged 7 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions server/svix-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub async fn run(cfg: Configuration, listener: Option<TcpListener>) {
// build our application with a route
let app = Router::new()
.nest("/api/v1", v1::router())
.merge(docs::router())
.layer(
ServiceBuilder::new().layer_fn(|service| IdempotencyService {
cache: cache.clone(),
Expand Down Expand Up @@ -135,3 +136,27 @@ pub async fn run(cfg: Configuration, listener: Option<TcpListener>) {
worker_loop.expect("Error initializing worker");
expired_message_cleaner_loop.expect("Error initializing expired message cleaner")
}

mod docs {
use axum::{
response::{Html, IntoResponse},
routing::get,
Json, Router,
};

pub fn router() -> Router {
Router::new()
svix-dylan marked this conversation as resolved.
Show resolved Hide resolved
.route("/docs", get(get_docs))
.route("/openapi.json", get(get_openapi_json))
svix-dylan marked this conversation as resolved.
Show resolved Hide resolved
}

async fn get_docs() -> Html<&'static str> {
Html(include_str!("static/docs.html"))
}

async fn get_openapi_json() -> impl IntoResponse {
svix-dylan marked this conversation as resolved.
Show resolved Hide resolved
let json: serde_json::Value =
serde_json::from_str(include_str!("static/openapi.json")).unwrap();
svix-dylan marked this conversation as resolved.
Show resolved Hide resolved
Json(json)
}
}
26 changes: 26 additions & 0 deletions server/svix-server/src/static/docs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<title>Svix API - 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">

<link rel="shortcut icon" href="https://fastapi.tiangolo.com/img/favicon.png">
svix-dylan marked this conversation as resolved.
Show resolved Hide resolved
<!--
ReDoc doesn't change outer page styles
-->
<style>
body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<redoc spec-url="/openapi.json"></redoc>
<script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
</body>
</html>
1 change: 1 addition & 0 deletions server/svix-server/src/static/openapi.json

Large diffs are not rendered by default.