mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 00:25:17 +00:00
Read configuration
This commit is contained in:
47
src/helpers/ConfigHelper.ts
Normal file
47
src/helpers/ConfigHelper.ts
Normal file
@ -0,0 +1,47 @@
|
||||
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 {
|
||||
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();
|
||||
}
|
@ -1,8 +1,12 @@
|
||||
import { ConfigurationHelper, conf } from "./helpers/ConfigHelper";
|
||||
|
||||
/**
|
||||
* Main project script
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
console.log("Comunic API v6\t@author Pierre HUBERT\t2019-" + new Date().getFullYear());
|
||||
console.info("Comunic API v6\t@author Pierre HUBERT\t2019-" + new Date().getFullYear());
|
||||
|
||||
console.info("Load configuration...");
|
||||
ConfigurationHelper.loadConf("config.json");
|
||||
|
Reference in New Issue
Block a user