app: Allow to configure the API base url

This commit is contained in:
traxys 2023-05-29 12:27:46 +02:00
parent ecea84d95b
commit d0313af5ba

View file

@ -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?;