Wulf / create-rust-app

Set up a modern rust+react web app by running one command.

Home Page:https://create-rust-app.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

release mode can't recognize .env file

opened this issue · comments

cargo run --release
......
thread 'main' panicked at 'No SECRET_KEY environment variable set!', /home/xxx/.cargo/registry/src/github.com-1ecc6299db9ec823/create-rust-app-8.0.2/src/lib.rs:65:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Although the .env does exist and has SECRET_KEY set and working fine with cargo run in dev mode.

commented

hey @zhenpingfeng thanks for reporting this. The .env file is only used in development. If you want this, add the following to your main.rs (you'll need the dotenv crate):

    // load .env in production
    #[cfg(not(debug_assertions))]
    {
        if dotenv::dotenv().is_err() {
            panic!("ERROR: Could not load environment variables from dotenv file");
        }
    }

I don't think we should add this as a default to all newly created projects because it leads to bad practice. For your use-case, it may be fine, but if you disagree and think it should be default, I'm willing to listen to your arguments!

commented

Closing for now, feel free to re-open :)