15815213711
2024-08-26 67b8b6731811983447e053d4396b3708c14dfe3c
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
const path = require('path');
 
/**
 * The configuration of ee application, can be access by `app.config`
 * @class Config
 * @since 1.0.0
 */
 
module.exports = appInfo => {
 
  const config = {
 
    /**
     * The environment of ee
     * @member {String} Config#env
     * @see {appInfo#env}
     * @since 1.0.0
     */
    env: appInfo.env,
 
    /**
     * The name of the application
     * @member {String} Config#name
     * @see {appInfo#name}
     * @since 1.0.0
     */
    name: appInfo.name,
 
    /**
     * The current directory of the application
     * @member {String} Config#baseDir
     * @see {appInfo#baseDir}
     * @since 1.0.0
     */
    baseDir: appInfo.baseDir,
 
    /**
     * The current HOME directory
     * @member {String} Config#HOME
     * @see {appInfo#HOME}
     * @since 1.0.0
     */
    HOME: appInfo.home,
 
    /**
     * The directory of server running. You can find `application_config.json` under it that is dumpped from `app.config`.
     * @member {String} Config#rundir
     * @default
     * @since 1.0.0
     */
    rundir: path.join(appInfo.baseDir, 'run'),
 
    /**
     * dump config
     *
     * It will ignore special keys when dumpConfig
     *
     * @member Config#dump
     * @property {Set} ignore - keys to ignore
     */
    dump: {
      ignore: new Set([
        'pass', 'pwd', 'passd', 'passwd', 'password', 'keys', 'masterKey', 'accessKey',
        // ignore any key contains "secret" keyword
        /secret/i,
      ]),
    },
 
    /**
     * application home directory
     * @member {String} Config#homeDir
     * @default
     * @since 1.0.0
     */
    homeDir: appInfo.home,
 
    /**
     * application data & logs directory by env
     * @member {String} Config#root
     * @default
     * @since 1.0.0
     */
    root: appInfo.root,
 
    /**
     * application data directory
     * @member {String} Config#appUserDataDir
     * @default
     * @since 1.0.0
     */
    appUserDataDir: appInfo.appUserDataDir,
 
    /**
     * system user home dir 
     * @member {String} Config#userHome
     */
    userHome: appInfo.userHome,
 
    /**
      * application version
      * @member {String} Config#appVersion
      */
    appVersion: appInfo.appVersion,
 
    /**
      * application package status
      * @member {boolean} Config#isPackaged
      */      
    isPackaged: appInfo.isPackaged,
 
    /**
      * application exec file dir
      * @member {String} Config#execDir
      */  
    execDir: appInfo.execDir
  };
 
  /**
   * logger options
   * @member Config#logger
   * @property {String} dir - directory of log files
   * @property {String} encoding - log file encoding, defaults to utf8
   * @property {String} level - default log level, could be: DEBUG, INFO, WARN, ERROR or NONE, defaults to INFO in production
   * @property {String} consoleLevel - log level of stdout, defaults to INFO in local serverEnv, defaults to WARN in unittest, defaults to NONE elsewise
   * @property {Boolean} disableConsoleAfterReady - disable logger console after app ready. defaults to `false` on local and unittest env, others is `true`.
   * @property {Boolean} outputJSON - log as JSON or not, defaults to false
   * @property {Boolean} buffer - if enabled, flush logs to disk at a certain frequency to improve performance, defaults to true
   * @property {String} errorLogName - file name of errorLogger
   * @property {String} coreLogName - file name of coreLogger
   * @property {String} agentLogName - file name of agent worker log
   * @property {Object} coreLogger - custom config of coreLogger
   * @property {Boolean} allowDebugAtProd - allow debug log at prod, defaults to false
   * @property {Boolean} enablePerformanceTimer - using performance.now() timer instead of Date.now() for more more precise milliseconds, defaults to false. e.g.: logger will set 1.456ms instead of 1ms.
   */
  config.logger = {
    type: 'application',
    dir: path.join(appInfo.root, 'logs'),
    encoding: 'utf8',
    env: appInfo.env,
    level: 'INFO',
    consoleLevel: 'INFO',
    disableConsoleAfterReady: appInfo.env !== 'local' && appInfo.env !== 'unittest',
    outputJSON: false,
    buffer: true,
    appLogName: `ee.log`,
    coreLogName: 'ee-core.log',
    agentLogName: 'ee-agent.log',
    errorLogName: `ee-error.log`,
    coreLogger: {},
    allowDebugAtProd: false,
    enablePerformanceTimer: false,
    rotator: 'none',
  };
 
  /**
   * customLogger options
   * @member Config#customLogger
   * 
   */  
  config.customLogger = {}
 
  /**
   * The option for httpclient
   * @member Config#httpclient
   * @property {Boolean} enableDNSCache - Enable DNS lookup from local cache or not, default is false.
   * @property {Boolean} dnsCacheLookupInterval - minimum interval of DNS query on the same hostname (default 10s).
   *
   * @property {Number} request.timeout - httpclient request default timeout, default is 5000 ms.
   *
   * @property {Boolean} httpAgent.keepAlive - Enable http agent keepalive or not, default is true
   * @property {Number} httpAgent.freeSocketTimeout - http agent socket keepalive max free time, default is 4000 ms.
   * @property {Number} httpAgent.maxSockets - http agent max socket number of one host, default is `Number.MAX_SAFE_INTEGER` @ses https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
   * @property {Number} httpAgent.maxFreeSockets - http agent max free socket number of one host, default is 256.
   *
   * @property {Boolean} httpsAgent.keepAlive - Enable https agent keepalive or not, default is true
   * @property {Number} httpsAgent.freeSocketTimeout - httpss agent socket keepalive max free time, default is 4000 ms.
   * @property {Number} httpsAgent.maxSockets - https agent max socket number of one host, default is `Number.MAX_SAFE_INTEGER` @ses https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
   * @property {Number} httpsAgent.maxFreeSockets - https agent max free socket number of one host, default is 256.
   */
  config.httpclient = {
    enableDNSCache: false,
    dnsCacheLookupInterval: 10000,
    dnsCacheMaxLength: 1000,
    request: {
      timeout: 5000,
    },
    httpAgent: {
      keepAlive: true,
      freeSocketTimeout: 4000,
      maxSockets: Number.MAX_SAFE_INTEGER,
      maxFreeSockets: 256,
    },
    httpsAgent: {
      keepAlive: true,
      freeSocketTimeout: 4000,
      maxSockets: Number.MAX_SAFE_INTEGER,
      maxFreeSockets: 256,
    },
  };
 
  /**
   * 应用模式配置
   */
  config.developmentMode = {
    default: 'vue',
    mode: {
      vue: {
        protocol: 'http://',
        hostname: 'localhost',
        port: 8080
      },
      react: {
        protocol: 'http://',
        hostname: 'localhost',
        port: 3000
      },
      html: {
        protocol: 'http://',
        hostname: 'localhost',
        indexPage: 'index.html'
      },
    }
  };
 
  /* 内置socket服务 */
  config.socketServer = {
    enable: false, // 是否启用
    port: 7070, // 默认端口(如果端口被使用,则随机获取一个)
    path: "/socket.io/", // 路径名称
    connectTimeout: 45000, // 客户端连接超时时间
    pingTimeout: 30000, // 心跳检测超时时间
    pingInterval: 25000, // 心跳检测间隔
    maxHttpBufferSize: 1e8, // 每条消息的数据大小 1M
    transports: ["polling", "websocket"], // http轮询和websocket
    cors: {
      origin: true, // http协议时,要设置跨域 类型 Boolean String RegExp Array Function
    }
  };
  
  /* 内置http服务 */
  config.httpServer = {
    enable: false, // 是否启用
    https: {
      enable: false,
      key: '',
      cert: ''
    },
    protocol: 'http://',
    host: 'localhost',
    port: 7071, // 默认端口(如果端口被使用,则随机获取一个)
    cors: {
      origin: "*"
    },
    body: {
      multipart: true, // 文件类型
    },
    filterRequest: {
      uris:  [],
      returnData: ''
    }
  };  
 
  /* 主进程加载的地址 */
  config.mainServer = {
    protocol: 'file://', // http:// | https:// | file://
    indexPath: '/public/dist/index.html',
    host: 'localhost',
    port: 7072, // 默认端口(如果端口被使用,则随机获取一个)
    open: false, // 是否开放0.0.0.0,默认关闭
    options: {},
    ssl: {
      key: '',
      cert: ''
    }
  }; 
 
  /**
   * 应用程序顶部菜单
   * boolean | string
   * true, false, 'dev-show'(dev环境显示,prod环境隐藏)
   */
  config.openAppMenu = true; 
 
  /**
   * 硬件加速
   */
  config.hardGpu = {
    enable: true
  };
 
  /**
   * TODO storage
   */
  config.storage = {
    dir: path.join(appInfo.root, 'data'),
  };
 
  /**
   * addons
   */
  config.addons = {
    window: {
      enable: true,
    }
  }; 
 
  /**
   * 异常捕获
   */
  config.exception = {
    mainExit: false,
    childExit: true,
    rendererExit: true,
  };
 
  /**
   * Cross-language service
   * 跨语言服务
   * 例如:执行go的二进制程序
   */
  config.cross = {};   
  
  /**
   * jobs
   */
  config.jobs = {
    messageLog: true
  };  
  
  return config;
};