mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-21 21:09:22 +00:00
Read configuration
This commit is contained in:
parent
a17ae688e4
commit
cc730eca90
10
config.json
Normal file
10
config.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"storageURL": "http://devweb.local/comunic/current/user_data/",
|
||||
"storagePath": "/home/pierre/Documents/projets_web/comunic/current/user_data/",
|
||||
"database": {
|
||||
"host": "localhost",
|
||||
"dbName": "comunic",
|
||||
"user": "pierre",
|
||||
"password": "pierre"
|
||||
}
|
||||
}
|
6
package-lock.json
generated
6
package-lock.json
generated
@ -4,6 +4,12 @@
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@types/node": {
|
||||
"version": "12.12.8",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.8.tgz",
|
||||
"integrity": "sha512-XLla8N+iyfjvsa0KKV+BP/iGSoTmwxsu5Ci5sM33z9TjohF72DEz95iNvD6pPmemvbQgxAv/909G73gUn8QR7w==",
|
||||
"dev": true
|
||||
},
|
||||
"typescript": {
|
||||
"version": "3.7.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.2.tgz",
|
||||
|
@ -10,5 +10,8 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"typescript": "^3.7.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^12.12.8"
|
||||
}
|
||||
}
|
||||
|
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");
|
||||
|
Loading…
Reference in New Issue
Block a user