Skip to content

Conversation

@lizidev
Copy link
Contributor

@lizidev lizidev commented Jul 24, 2025

Allows us to specify the corresponding configuration at compile time, and no longer needs to provide environment variables when executing executable files (exe generated in ssr mode).

// Before
1. Use runtime environment variables. (`std::env::var`)
2. Default value.

// After
1. Use runtime environment variables. (`std::env::var`)
2. Use compile-time environment variables. (`option_env!`)
3. Default value.

@benwis
Copy link
Contributor

benwis commented Aug 7, 2025

Hi @lizidev, thanks for the PR.

I'm not sure how I feel about this PR. If I'm reading this correctly, if an environment variable is set during compilation(like with cargo_leptos), then when the binary is executed later it will use those values and not the defaults if run in, say, a deployment environment?

To me that seems suboptimal, as deployment variables will in most cases be different than the ones set during compilation. But if you're building in a docker environment you could set production values, but often that environment is separate from the web host one too. I'm not sure I can think of another web framework that behaves in a similar way here.

I'll have to think on this one a bit

@lizidev
Copy link
Contributor Author

lizidev commented Aug 12, 2025

It reads the runtime environment variables first, so it doesn't affect setting new environment variables in the deployment environment.

This PR primarily allows me to customize variables at compile time, and then execute the executable directly in the deployment environment (saves the step of setting environment variables).

I'm not sure I can think of another web framework that behaves in a similar way here.

Currently, both Vite and Dioxus CLI behave in this way.

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

Successfully merging this pull request may close these issues.

2 participants