forked from chowa/ejyy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ts
240 lines (231 loc) · 5.95 KB
/
config.ts
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/**
* +----------------------------------------------------------------------
* | 「e家宜业」 —— 助力物业服务升级,用心服务万千业主
* +----------------------------------------------------------------------
* | Copyright (c) 2020-2022 https://www.chowa.cn All rights reserved.
* +----------------------------------------------------------------------
* | Licensed 未经许可不能去掉「e家宜业」和「卓瓦科技」相关版权
* +----------------------------------------------------------------------
* | Author: [email protected]
* +----------------------------------------------------------------------
*/
import Mysql from 'mysql';
import Knex from 'knex';
import yaml from 'js-yaml';
import fs from 'fs';
import path from 'path';
import cwlog from 'chowa-log';
interface Config {
name: string;
debug: boolean;
server: {
port: number;
name: string;
};
mysqlConfig: Mysql.ConnectionConfig & Knex.ConnectionConfig;
redis: {
host: string;
port: number;
password: string;
};
token: {
mp: string;
pc: string;
};
wechat: {
ump: {
appid: string;
secret: string;
};
oa: {
appid: string;
secret: string;
token: string;
key: string;
};
pay: {
mch_id: string;
prodHost: string;
devHost: string;
payExpire: number;
refoundExpire: number;
key: string;
certPath: string;
};
web: {
appid: string;
secret: string;
};
pmp: {
appid: string;
secret: string;
};
};
map: {
key: string;
};
session: {
key: string;
maxAge: number;
signed: boolean;
};
community: {
expire: number;
};
aliyun: {
accessKeyId: string;
accessKeySecret: string;
oss: {
bucket: string;
region: string;
host?: string;
};
};
crypto: {
key: string;
iv: string;
};
smtp: {
host: string;
port: number;
secure: boolean;
user?: string;
password?: string;
to?: string;
};
inited: boolean;
}
interface CustomConfig {
[key: string]: any;
}
function generateConfig(): Config {
let customConfig = <CustomConfig>{};
try {
customConfig = yaml.load(fs.readFileSync(path.join(process.cwd(), '.ejyyrc'), 'utf-8'));
} catch (e) {
cwlog.error('未检测到配置文件,程序退出');
process.exit();
}
const mysqlConfig: Mysql.ConnectionConfig & Knex.ConnectionConfig = {
host: '',
port: 3306,
user: 'root',
password: '',
database: '',
...customConfig.mysql,
supportBigNumbers: true,
typeCast: (field, next) => {
// 数据库内所有字段只要是content的都是json内容
if (field.type === 'BLOB' && field.name === 'content') {
return JSON.parse(field.string());
}
return next();
}
};
return {
name: 'ejyy',
debug: process.env.NODE_ENV !== 'production',
server: {
port: 6688,
name: 'e家宜业',
...customConfig.server
},
mysqlConfig,
redis: {
host: '',
port: 6379,
password: '',
...customConfig.redis
},
token: {
mp: 'ejyy-mp-token',
pc: 'ejyy-pc-token',
...customConfig.token
},
wechat: {
// 小程序
ump: {
appid: '',
secret: '',
...(customConfig.wechat ? customConfig.wechat.ump : {})
},
// 公众号
oa: {
appid: '',
secret: '',
token: '',
key: '',
...(customConfig.wechat ? customConfig.wechat.oa : {})
},
// 支付
pay: {
mch_id: '',
prodHost: '',
devHost: '',
// 支付时效
payExpire: 30 * 60 * 1000,
// 退款时效
refoundExpire: 15 * 1000 * 24 * 60 * 60,
key: '',
certPath: '',
...(customConfig.wechat ? customConfig.wechat.pay : {})
},
// 物业web
web: {
appid: '',
secret: '',
...(customConfig.wechat ? customConfig.wechat.web : {})
},
// 物业端小程序
pmp: {
appid: '',
secret: '',
...(customConfig.wechat ? customConfig.wechat.pmp : {})
}
},
// 地图
map: {
key: '',
...customConfig.map
},
session: {
key: 'ejyy:session',
maxAge: 1000 * 60 * 30,
signed: false,
...customConfig.session
},
// 二维码
community: {
expire: 5 * 60 * 1000,
...customConfig.community
},
aliyun: {
accessKeyId: '',
accessKeySecret: '',
// 对象存储
oss: {
bucket: '',
region: '',
host: ''
},
...customConfig.aliyun
},
// 各类可以解密加密
crypto: {
key: '',
iv: '',
...customConfig.crypto
},
smtp: {
host: '',
port: 465,
secure: true,
user: '',
password: '',
to: '',
...customConfig.smtp
},
inited: false
};
}
export default generateConfig();