Skip to content

Commit

Permalink
feat: replace variables in config
Browse files Browse the repository at this point in the history
  • Loading branch information
philipparndt committed Jan 6, 2024
1 parent f84215a commit a420886
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/lib/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,20 @@ export const applyDefaults = (config: any) => {
} as Config
}

export const replaceEnvVariables = (input: string) => {
const envVariableRegex = /\${([^}]+)}/g

return input.replace(envVariableRegex, (_, envVarName) => {
return process.env[envVarName] || ""
})
}

export const loadConfig = (file: string) => {
const buffer = fs.readFileSync(file)
applyConfig(JSON.parse(buffer.toString()))
return appConfig
const effectiveConfig = replaceEnvVariables(buffer.toString())
log.trace("Using config", effectiveConfig)
log.trace("parsing config")
applyConfig(JSON.parse(effectiveConfig))
}

export const applyConfig = (config: any) => {
Expand Down

0 comments on commit a420886

Please sign in to comment.