Created
July 14, 2020 01:39
-
-
Save e06widu/aaed84af204caa01d7e3f81b10eef5d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Configuration } from './configuration'; | |
/** | |
* Expose configuration values to the application | |
*/ | |
export class ConfigurationManager { | |
private static manager: ConfigurationManager; | |
private appConfig!: Configuration; | |
static getSingletonInstance(): ConfigurationManager { | |
return ConfigurationManager.manager = new ConfigurationManager(); | |
} | |
get connectionString(): string { | |
return `mssql://${this.appConfig.dbConfiguration.username}:${this.appConfig.dbConfiguration.password}@${this.appConfig.dbConfiguration.host}/${this.appConfig.dbConfiguration.database}`; | |
} | |
get connectionConfig(): any { | |
return { | |
server: this.appConfig.dbConfiguration.host, | |
authentication: { | |
type: 'default', | |
options: { | |
userName: this.appConfig.dbConfiguration.username, | |
password: this.appConfig.dbConfiguration.password | |
} | |
}, | |
options: { | |
database: this.appConfig.dbConfiguration.database | |
} | |
}; | |
} | |
private constructor() { | |
this.loadConfigFromEnvironmentVariables(); | |
} | |
private loadConfigFromEnvironmentVariables(): void { | |
this.appConfig = { | |
dbConfiguration: { | |
database: process.env.DB_NAME, | |
host: process.env.DB_HOST, | |
password: process.env.DB_PWD, | |
username: process.env.DB_USER | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment