blob: 3ac8129efdcb1f49b2a41919906c2e5404706059 [file] [log] [blame]
import dotenv from 'dotenv'
dotenv.config()
export default class Configuration {
static get CONFIG () {
return {
clientId: '$VUE_APP_CLIENT_ID',
custosApiUrl: '$VUE_APP_CUSTOS_API_URL',
superClientId: '$VUE_APP_SUPER_CLIENT_ID',
underMaintenance: '$VUE_APP_UNDER_MAINTENANCE'
}
}
static value (name) {
if (!(name in this.CONFIG)) {
console.log(`Configuration: There is no key named "${name}"`)
return
}
const value = this.CONFIG[name]
if (!value) {
console.log(`Configuration: Value for "${name}" is not defined`)
return
}
if (value.startsWith('$VUE_APP_')) {
// value was not replaced, it seems we are in development.
// Remove $ and get current value from process.env
const envName = value.substr(1)
const envValue = process.env[envName]
if (envValue) {
return envValue
} else if (window.serverConfig && window.serverConfig[envName]) {
// Check if the variables is set by the portal server
return window.serverConfig[envName];
} else {
console.log(`Configuration: Environment variable "${envName}" is not defined`)
}
} else {
// value was already replaced, it seems we are in production.
return value
}
}
}