first commit

This commit is contained in:
pakerpale
2020-08-28 02:08:23 +09:00
commit b8899d1d4e
24 changed files with 3865 additions and 0 deletions

60
config/Config.js Normal file
View File

@@ -0,0 +1,60 @@
const commandLineArgs = require('command-line-args'),
logger = require("logops");
class Config {
constructor() {
this.options = {}
this.requires = ['env']
this.init()
process.env.TZ = 'Europe/Berlin'
}
init() {
try {
this.options = commandLineArgs([
{ name: 'env', alias: 'e', type: String, defaultValue: ['production'] },
{ name: 'host', type: String },
{ name: 'port', type: Number },
{ name: 'database', alias: 'd', type: String },
{ name: 'username', alias: 'u', type: String },
{ name: 'password', alias: 'p', type: String },
{ name: 'redis', alias: 'r', type: String }
]);
this.validate()
} catch (e) {
logger.debug('Command line arguments interpret failed :', e.message)
logger.debug('expected arguments : ', JSON.stringify(this.requires))
process.exit(1)
}
}
validate() {
let options = {}
for (let key in this.options) {
if (this.options[key]) {
options[key] = this.options[key]
delete this.requires[this.requires.indexOf(key)]
}
}
if (options.env == 'development') {
logger.setLevel("DEBUG")
logger.format = logger.formatters.dev;
}else {
logger.setLevel("WARN")
}
console.log(options)
this.requires = this.requires.filter(function (el) {
return el != null;
})
if (this.requires.length) {
logger.debug('Process terminated invalid required arguments: ', JSON.stringify(requires))
process.exit(1)
}
}
}
let config = new Config;
module.exports = config.options

39
config/config.json Normal file
View File

@@ -0,0 +1,39 @@
{
"development": {
"username": "root",
"password": null,
"database": "iblogis_legacy",
"host": "localhost",
"dialect": "mysql",
"pool": {
"max": 5,
"min": 0,
"acquire": 30000,
"idle": 10000,
"charset": "utf8"
},
"timezone": "+02:00"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"username": "iblogis",
"password": "dkrnffk73**",
"database": "iblogis",
"host": "87.106.21.246",
"dialect": "mysql",
"pool": {
"max": 5,
"min": 0,
"acquire": 30000,
"idle": 10000,
"charset": "utf8"
},
"timezone": "+02:00"
}
}