From 6c915ef56d8137239e6740ae4462fd35cc8f39ea Mon Sep 17 00:00:00 2001 From: antifallobst Date: Wed, 4 Oct 2023 22:36:27 +0200 Subject: [PATCH] feat: added compile time environment variable for setting the api url this allows easy local testing --- src/backend/mod.rs | 9 +-------- src/main.rs | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/backend/mod.rs b/src/backend/mod.rs index ec33bd7..00c1660 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -39,20 +39,13 @@ pub struct Session { impl Default for Session { fn default() -> Self { Self { - base_url: "https://api.nerdcult.net".to_owned(), + base_url: option_env!("NC_API_URL").unwrap_or("https://api.nerdcult.net").to_string(), auth_token: get_auth_cookie(), } } } impl Session { - pub fn new(base_url: String) -> Self { - Self { - base_url, - auth_token: get_auth_cookie(), - } - } - pub fn login( &self, username: String, diff --git a/src/main.rs b/src/main.rs index f6b13de..53709cc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,7 +43,7 @@ pub struct Callbacks { #[function_component] fn App() -> Html { // let state = use_state(Session::default); - let state = use_state(|| Session::new("http://localhost:8080".to_string())); + let state = use_state(Session::default); let cloned_state = state.clone(); let callbacks = use_state(move || Callbacks {