-
Notifications
You must be signed in to change notification settings - Fork 20
/
config.js
71 lines (69 loc) · 1.84 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var config = {
// baidu access data
'deal' : 0,
// sql access data
'sqltype' : '',
'host' : '',
'username' : '',
'password' : '',
'port' : '',
'database' : '',
'prefix' : '',
// service
'ssl' : false
};
var fs = require("fs");
var loaded = false;
exports.load = function load(){
if (loaded) return true;
/* if (! fs.exists('./config.json')){
console.log('./config.json is not exists.')
return false;
} */
var cfg = fs.readFileSync('./config.json');
cfg = JSON.parse(cfg);
config['ak'] = String(cfg['ak']);
config['sk'] = String(cfg['sk']);
config['deal'] = parseInt(cfg['deal']);
config['sqltype'] = String(cfg['sqltype']);
config['host'] = String(cfg['host']);
config['username'] = String(cfg['username']);
config['password'] = String(cfg['password']);
config['port'] = String(cfg['port']);
config['database'] = String(cfg['database']);
config['prefix'] = String(cfg['prefix']);
config['secret'] = String(cfg['secret']);
if (String(cfg['ssl'])=='true') config['ssl'] = true;
else
if (String(cfg['ssl'])=='false') config['ssl'] = false;
else
{
console.log('bad ssl value');
return false;
}
loaded = true;
return true;
}
function check_x(x){
if (x == 'ak' ||
x == 'sk' ||
x == 'deal' ||
x == 'sqltype' ||
x == 'host' ||
x == 'username' ||
x == 'password' ||
x == 'port' ||
x == 'database' ||
x == 'prefix' ||
x == 'open' ||
x == 'secret' ||
x == 'ssl'
)
return true;
return false;
}
exports.get = function get(x){
if (!check_x(x)) return false;
return config[x];
}
if (!loaded) exports.load();