This commit is contained in:
2024-09-02 12:17:22 -04:00
parent 6be8f81fa9
commit 16be83a0de
3 changed files with 38 additions and 2 deletions
+14 -2
View File
@@ -8,7 +8,7 @@ use std::{
use axum::{
error_handling::HandleErrorLayer,
extract::Path,
http::{header, StatusCode},
http::{header, HeaderValue, Method, StatusCode},
response::IntoResponse,
routing::get,
BoxError, Router,
@@ -16,6 +16,7 @@ use axum::{
use base64::{engine::general_purpose::STANDARD, Engine};
use tower::{buffer::BufferLayer, limit::rate::RateLimitLayer, ServiceBuilder};
use tower_http::cors::CorsLayer;
#[tokio::main]
async fn main() {
@@ -49,6 +50,11 @@ fn app() -> Router {
.layer(BufferLayer::new(1024))
.layer(RateLimitLayer::new(5, Duration::from_secs(1))),
)
.layer(
CorsLayer::new()
.allow_origin("*".parse::<HeaderValue>().unwrap())
.allow_methods([Method::GET]),
)
.route("/:command", get(command))
}
@@ -71,7 +77,13 @@ impl From<FromUtf8Error> for ManserveErr {
}
fn get_man_loc(command: &str) -> Result<String, ManserveErr> {
let output = Command::new("man").args(["-w", command]).output()?;
let output = match Command::new("man").args(["-w", command]).output() {
Ok(output) => output,
Err(error) => {
println!("{error}");
return Err(error.into());
}
};
if !output.status.success() {
return Err(ManserveErr::NotFound);
}