diff --git a/app/src/main.rs b/app/src/main.rs index 8924165..0073e45 100644 --- a/app/src/main.rs +++ b/app/src/main.rs @@ -10,6 +10,17 @@ use crate::sidebar::RegaladeSidebar; mod sidebar; +const API_ROUTE: &str = match option_env!("REGALADE_API_SERVER_BASE") { + None => "http://localhost:8085", + Some(v) => v, +}; + +macro_rules! api { + ($($arg:tt)*) => { + &format!("{API_ROUTE}/api/{}", format_args!($($arg)*)) + }; +} + #[derive(Routable, Debug, Clone, Copy, PartialEq, Eq)] enum Route { #[at("/")] @@ -150,7 +161,7 @@ fn switch(route: Route) -> Html { } async fn do_login(username: String, password: String) -> anyhow::Result<()> { - let rsp = gloo_net::http::Request::post("http://localhost:8085/api/login") + let rsp = gloo_net::http::Request::post(api!("login")) .json(&LoginRequest { username, password })? .send() .await?;