From 94c4428bb0d0eca3e3da1a9ac29148017df6c3ba Mon Sep 17 00:00:00 2001 From: Radical Date: Thu, 29 May 2025 20:41:50 +0200 Subject: [PATCH] feat: add base_path to api Lets you replace /api with whatever you want! --- src/api/mod.rs | 4 ++-- src/config.rs | 3 +++ src/main.rs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/api/mod.rs b/src/api/mod.rs index 87c1c14..4cad2fa 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -6,6 +6,6 @@ use actix_web::web; mod v1; mod versions; -pub fn web() -> Scope { - web::scope("/api").service(v1::web()).service(versions::get) +pub fn web(path: &str) -> Scope { + web::scope(path.trim_end_matches('/')).service(v1::web()).service(versions::get) } diff --git a/src/config.rs b/src/config.rs index 8a274b4..464c98d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -38,6 +38,7 @@ pub struct CacheDatabase { struct WebBuilder { ip: Option, port: Option, + base_path: Option, frontend_url: Url, _ssl: Option, } @@ -85,6 +86,7 @@ impl ConfigBuilder { let web = Web { ip: self.web.ip.unwrap_or(String::from("0.0.0.0")), port: self.web.port.unwrap_or(8080), + base_path: self.web.base_path.unwrap_or("".to_string()), frontend_url: self.web.frontend_url, }; @@ -146,6 +148,7 @@ pub struct Config { pub struct Web { pub ip: String, pub port: u16, + pub base_path: String, pub frontend_url: Url, } diff --git a/src/main.rs b/src/main.rs index 0f94be8..5670e7b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -150,7 +150,7 @@ async fn main() -> Result<(), Error> { App::new() .app_data(web::Data::new(data.clone())) .wrap(cors) - .service(api::web()) + .service(api::web(&data.config.web.base_path)) }) .bind((web.ip, web.port))? .run()