From d0313af5ba1f8625122b88910744882a88bc7b8a Mon Sep 17 00:00:00 2001 From: traxys Date: Mon, 29 May 2023 12:27:46 +0200 Subject: [PATCH] app: Allow to configure the API base url --- app/src/main.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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?;