1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-12-01 17:56:28 +00:00
comunicapiv2/src/helpers/ConfigHelper.ts

48 lines
867 B
TypeScript
Raw Normal View History

2019-11-21 15:28:48 +00:00
import { readFileSync } from "fs";
/**
* Configuration helper
*
* @author Pierre HUBERT
*/
export interface DatabaseConfiguration {
host : string,
dbName : string,
user : string,
password : string,
dbPrefix : string
}
export interface Configuration {
2019-11-21 17:06:50 +00:00
port: number,
2019-11-21 15:28:48 +00:00
storageURL : string,
storagePath : string,
database : DatabaseConfiguration,
}
export class ConfigurationHelper {
private static conf : Configuration;
public static getConf() : Configuration {
return this.conf;
}
/**
* Load configuration from a specified configuration file
*
* @param fileName Configuration file to load
*/
public static loadConf(fileName : string) {
this.conf = JSON.parse(readFileSync(fileName, {encoding: "utf-8"}));
}
}
/**
* Get project configuration
*/
export function conf() : Configuration {
return ConfigurationHelper.getConf();
}