You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think we can provide a little more clarity on loading env files from a string by changing the name of this method so it's clear that this is useful outside of test scenarios
Why would you want to load an environment variable from a string in a production app?
Ideally .env files are not baked into the app package assets because they are easy to get access to. We can provide a little bit of obfuscation by loading them into the binary as a compile time string.
// .vscode/launch.json{"version": "0.2.0","configurations": [{"name": "app","request": "launch","type": "dart","args": ["--dart-define=ENV=$(cat .env | base64)"]// pull the .env file from filesystem and pipe it to const string via base64}]}
// config.dartvoidmain() {
const b64env =String.fromEnvironment('ENV'); // load the base64 encoded .env file
dotenv.testLoad(fileInput: b64env.fromBase64()); // load it into dotenv, << this is where I think we can add some clarity
config =Config();
}
classConfig {
final environment =Environment.values.byName(dotenv.get('ENVIRONMENT'));
final fastApiPort = dotenv.getInt('FASTAPI_PORT').assertPortNumber();
final fastApiHost = dotenv.get('FASTAPI_HOST').assertNotEmpty();
final fastApiKey = dotenv.get('FASTAPI_KEY').assertNotEmpty();
}
extensionStringExtensionsonString {
StringfromBase64() {
return utf8.decode(base64.decode(this));
}
}
The text was updated successfully, but these errors were encountered:
I think we can provide a little more clarity on loading env files from a string by changing the name of this method so it's clear that this is useful outside of test scenarios
Why would you want to load an environment variable from a string in a production app?
Ideally .env files are not baked into the app package assets because they are easy to get access to. We can provide a little bit of obfuscation by loading them into the binary as a compile time string.
The text was updated successfully, but these errors were encountered: