Hi guys,
I would like to know if anyone had a similar problem or knows a workaround to it.
I have a Dioxus project which needs to use use variables from a .env file.
Below is the code:
extern crate dotenv;
use dioxus::{logger::tracing::info, prelude::*};
use dotenv::dotenv;
use std::env;
fn main() {
dotenv().ok();
let hidden = env::var("URL_PROJECT_SUPABASE");
match hidden {
Ok(val) => println!("hidden: {val}"),
Err(e) => println!("hidden: {e}"),
}
dioxus::launch(App);
}
fn App() -> Element {
dotenv().ok();
let hidden = env::var("URL_PROJECT_SUPABASE");
rsx! {
document::Stylesheet { href: CSS }
match hidden {
Ok(val) => rsx!(div{"hidden: {val}"}),
Err(e) => rsx!(div{"hidden: {e}"}),
}
}
}
When I try to print the variable in rust with cargo run, it successfully prints "hidden: variable_details".
However, when I run the Dioxus project with dx serve --platform web, it renders "hidden: environment variable not found
" on the web page.
How can I make the web page render the correct details from the .env file?