-
Notifications
You must be signed in to change notification settings - Fork 0
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
OpenAPI Playground #27
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
DATABASE_URL=postgres://mina:whatever@localhost:5432/archive | ||
RUST_LOG=debug,error,mina_mesh=info | ||
RUST_ENV=production |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ use clap::Args; | |
use paste::paste; | ||
use tokio::net::TcpListener; | ||
|
||
use crate::{util::Wrapper, MinaMesh, MinaMeshConfig}; | ||
use crate::{playground::handle_playground, util::Wrapper, MinaMesh, MinaMeshConfig}; | ||
|
||
#[derive(Debug, Args)] | ||
#[command(about = "Start the Mina Mesh Server.")] | ||
|
@@ -23,12 +23,17 @@ pub struct ServeCommand { | |
host: String, | ||
#[arg(default_value = "3000")] | ||
port: u16, | ||
#[arg(env, long)] | ||
playground: bool, | ||
#[arg(env = "RUST_ENV", long)] | ||
rust_env: String, | ||
Comment on lines
+26
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that having
|
||
} | ||
|
||
impl ServeCommand { | ||
pub async fn run(self) -> Result<()> { | ||
tracing_subscriber::fmt::init(); | ||
let mina_mesh = self.config.to_mina_mesh().await?; | ||
let router = Router::new() | ||
let mut router = Router::new() | ||
.route("/account/balance", post(handle_account_balance)) | ||
.route("/block", post(handle_block)) | ||
.route("/call", post(handle_call)) | ||
|
@@ -47,8 +52,11 @@ impl ServeCommand { | |
.route("/network/options", post(handle_network_options)) | ||
.route("/network/status", post(handle_network_status)) | ||
.with_state(Arc::new(mina_mesh)); | ||
if self.rust_env == "development" || self.playground { | ||
router = router.route("/", get(handle_playground)); | ||
} | ||
let listener = TcpListener::bind(format!("{}:{}", self.host, self.port)).await?; | ||
tracing::debug!("listening on {}", listener.local_addr()?); | ||
tracing::info!("listening on http://{}", listener.local_addr()?); | ||
serve(listener, router).await?; | ||
Ok(()) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ mod commands; | |
mod config; | ||
mod error; | ||
mod graphql; | ||
mod playground; | ||
mod util; | ||
|
||
pub use api::*; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use axum::{ | ||
debug_handler, | ||
response::{Html, IntoResponse}, | ||
}; | ||
|
||
#[debug_handler] | ||
pub async fn handle_playground() -> impl IntoResponse { | ||
let html = format!( | ||
r#" | ||
<!DOCTYPE html> | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>{title}</title> | ||
<meta charset="utf-8" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, initial-scale=1" /> | ||
<style> | ||
body {{ | ||
margin: 0; | ||
}} | ||
</style> | ||
</head> | ||
<body> | ||
<script | ||
id="api-reference"></script> | ||
<script> | ||
var configuration = {{ | ||
theme: 'deepSpace', | ||
customCss: `{scalar_css}`, | ||
spec: {{ | ||
url: '{spec_url}' | ||
}} | ||
}} | ||
|
||
var apiReference = document.getElementById('api-reference') | ||
apiReference.dataset.configuration = JSON.stringify(configuration) | ||
</script> | ||
<script>{scalar_js}</script> | ||
</body> | ||
</html> | ||
"#, | ||
scalar_js = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/static/scalar.standalone.min.js")), | ||
scalar_css = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/static/rust-theme.css")), | ||
title = "MinaMesh Playground", | ||
spec_url = OPENAPI_SPEC | ||
); | ||
Html(html) | ||
} | ||
|
||
static OPENAPI_SPEC: &str = | ||
"https://raw.githubusercontent.com/coinbase/mesh-specifications/7f9f2f691f1ab1f7450e376d031e60d997dacbde/api.json"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes ambiguous error when there's no
.env
file: