-
Notifications
You must be signed in to change notification settings - Fork 140
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
Dynamic default values #237
Comments
Would this be better implemented with a hook function instead of string interpolation? EDIT: there's nothing stopping you from using native JS variables and string interp. |
I would also like to use some computed default values, based on real values of other settings. I have put some workaround, but it would be nice to have the capacity to put a function instead of a static value in the defaults. |
Hi guys... any update on this? @ncjones I also have the same requirements, how did manage to get around yours? |
I only use my environment name for dynamic defaults so I just have a special environment variable for this: // src/config/schema.js
const env = process.env['ENV'] || 'local'
module.exports = {
gcpProject: {
format: String,
default: `my-app-${env}`,
env: 'GCP_PROJECT',
}
} |
Actually you can with : #110 but :
In my opinion, the change should be done only after convict thing, not in live during the loading. This will add too many loop, we should check for each env change. It is very simple to make a recursive function at the end. But if you really don't want to do with your own function. PR an convict.addCompiler('value', (v) => { /* ... */ })
config.load({
gcpProject: {
format: String,
default: `my-app-${env}`,
env: 'GCP_PROJECT',
}
})
config.compile()
config.validate() |
I'd like to be able to define config defaults in terms of other configs. For example, the schema could allow a variable expansion syntax like the following:
In the above case the call to
config.get('baseUrl')
, with no other configs defined, would return'http://test.my-domain/'
.The text was updated successfully, but these errors were encountered: