-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stats): Swagger endpoint (#1007)
serving as a static file
- Loading branch information
Showing
7 changed files
with
433 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
} |
Oops, something went wrong.