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

feat(stats): Swagger endpoint #1007

Merged
merged 7 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions libs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"blockscout-auth",
"blockscout-client/crate",
"blockscout-db",
"endpoints/swagger",
"blockscout-service-launcher",
"display-bytes",
"env-collector",
Expand Down
15 changes: 15 additions & 0 deletions libs/endpoints/swagger/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "blockscout-endpoint-swagger"
version = "0.1.0"
description = "Configuration tools for enabling swagger endpoint"
license = "MIT"
repository = "https://github.com/blockscout/blockscout-rs"
keywords = ["blockscout", "service", "http", "microservices", "swagger", "endpoint"]
categories = ["web-programming::http-server"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
actix-web = "4"
actix-files = "0.6.6"
20 changes: 20 additions & 0 deletions libs/endpoints/swagger/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::{path::PathBuf, sync::Arc};

use actix_files::NamedFile;
use actix_web::{web::get, HttpRequest, Result};

async fn serve_swagger_from(path: Arc<PathBuf>, _req: HttpRequest) -> Result<NamedFile> {
Ok(NamedFile::open(path.as_ref())?)
}

pub fn route_swagger(
service_config: &mut actix_web::web::ServiceConfig,
swagger_file_path: PathBuf,
route: &str,
) {
let path = Arc::new(swagger_file_path);
let serve_swagger = move |req: HttpRequest| serve_swagger_from(path.clone(), req);
service_config.configure(|config| {
config.route(route, get().to(serve_swagger));
});
}
Loading
Loading