Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load .env in cwd #93

Open
Dog2657 opened this issue May 5, 2024 · 0 comments
Open

Unable to load .env in cwd #93

Dog2657 opened this issue May 5, 2024 · 0 comments

Comments

@Dog2657
Copy link

Dog2657 commented May 5, 2024

I'm unable to access my .env file which is placed in the cwd. Only in docker compose with the env_file set can I access my env vars.

My project layout

.
├── .env
├── app/
│   ├── src/
│   ├── build.rs
│   ├── Cargo.lock
│   ├── Cargo.toml
│   └── Dockerfile
└── docker-compose.yml

My code

#[macro_use] extern crate rocket;

mod lib { 
    pub mod templator;
}

mod signup;

use dotenv;

use std::env;

#[launch]
fn rocket() -> _ {
    dotenv::dotenv().ok();

    let my_var = env::var("Discord-Client-Id").expect("MY_VAR not found");

    println!("\n\nMY_VAR: {}\n\n", my_var);

    rocket::build()
        .mount("/", signup::get_routes())
}

Output

MY_VAR not found: NotPresent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant