Skip to content

Commit

Permalink
feat(stats): Swagger endpoint (#1007)
Browse files Browse the repository at this point in the history
serving as a static file
  • Loading branch information
bragov4ik authored Aug 23, 2024
1 parent 7b0bee8 commit 2c2cd26
Show file tree
Hide file tree
Showing 7 changed files with 433 additions and 34 deletions.
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

0 comments on commit 2c2cd26

Please sign in to comment.