Skip to content

Instantly share code, notes, and snippets.

@e06widu
Created July 14, 2020 01:39
Show Gist options
  • Save e06widu/aaed84af204caa01d7e3f81b10eef5d3 to your computer and use it in GitHub Desktop.
Save e06widu/aaed84af204caa01d7e3f81b10eef5d3 to your computer and use it in GitHub Desktop.
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