feat: add base_path to api

Lets you replace /api with whatever you want!
This commit is contained in:
Radical 2025-05-29 20:41:50 +02:00
parent 3c5f3fd654
commit 94c4428bb0
3 changed files with 6 additions and 3 deletions

View file

@ -6,6 +6,6 @@ use actix_web::web;
mod v1; mod v1;
mod versions; mod versions;
pub fn web() -> Scope { pub fn web(path: &str) -> Scope {
web::scope("/api").service(v1::web()).service(versions::get) web::scope(path.trim_end_matches('/')).service(v1::web()).service(versions::get)
} }

View file

@ -38,6 +38,7 @@ pub struct CacheDatabase {
struct WebBuilder { struct WebBuilder {
ip: Option<String>, ip: Option<String>,
port: Option<u16>, port: Option<u16>,
base_path: Option<String>,
frontend_url: Url, frontend_url: Url,
_ssl: Option<bool>, _ssl: Option<bool>,
} }
@ -85,6 +86,7 @@ impl ConfigBuilder {
let web = Web { let web = Web {
ip: self.web.ip.unwrap_or(String::from("0.0.0.0")), ip: self.web.ip.unwrap_or(String::from("0.0.0.0")),
port: self.web.port.unwrap_or(8080), port: self.web.port.unwrap_or(8080),
base_path: self.web.base_path.unwrap_or("".to_string()),
frontend_url: self.web.frontend_url, frontend_url: self.web.frontend_url,
}; };
@ -146,6 +148,7 @@ pub struct Config {
pub struct Web { pub struct Web {
pub ip: String, pub ip: String,
pub port: u16, pub port: u16,
pub base_path: String,
pub frontend_url: Url, pub frontend_url: Url,
} }

View file

@ -150,7 +150,7 @@ async fn main() -> Result<(), Error> {
App::new() App::new()
.app_data(web::Data::new(data.clone())) .app_data(web::Data::new(data.clone()))
.wrap(cors) .wrap(cors)
.service(api::web()) .service(api::web(&data.config.web.base_path))
}) })
.bind((web.ip, web.port))? .bind((web.ip, web.port))?
.run() .run()