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
const EeAppCore = require('../core/index').EeCore;
const EE_PATH = Symbol.for('ee#eePath');
const path = require('path');
const EE_LOADER = Symbol.for('ee#loader');
const AppLoader = require('./appLoader');
const HttpClient = require('../httpclient');
const HTTPCLIENT = Symbol('EeApplication#httpclient');
const LOGGERS = Symbol('EeApplication#loggers');
const Log = require('../log');
const Conf = require('../config');
 
class BaseApp extends EeAppCore {
  constructor (options = {}) {
 
    super(options);
 
    this.loader.loadConfig();
    
    
    // [todo] 缓存配置
    Conf.setAll(this.config);
 
    this.loader.load();
 
    this.HttpClient = HttpClient;
  }
 
  get [EE_PATH]() {
    return path.join(__dirname, '..');
  }
 
  get [EE_LOADER]() {
    return AppLoader;
  }
 
  /**
   *  loggers
   * @member {Object}
   * @since 1.0.0
   */
  get loggers() {
    if (!this[LOGGERS]) {
      this[LOGGERS] = Log.create(this.config);
    }
    return this[LOGGERS];
  }
 
  /**
   * Get logger by name, it's equal to app.loggers['name'],
   * but you can extend it with your own logical.
   * @param {String} name - logger name
   * @return {Logger} logger
   */
  getLogger(name) {
    return this.loggers[name] || null;
  }
 
  /**
   * application logger, log file is `$HOME/logs/ee.log`
   * @member {Logger}
   * @since 1.0.0
   */
  get logger() {
    return this.getLogger('logger');
  }
 
  /**
   * core logger for framework and plugins, log file is `$HOME/logs/ee-core.log`
   * @member {Logger}
   * @since 1.0.0
   */
  get coreLogger() {
    return this.getLogger('coreLogger');
  }
  
  /**
   * @class curl
   * @since 1.0.0
   */
  curl(url, opts) {
    return this.httpclient.request(url, opts);
  }
 
  /**
   * HttpClient instance
   * @see https://github.com/node-modules/urllib
   * @member {HttpClient}
   */
  get httpclient() {
    if (!this[HTTPCLIENT]) {
      this[HTTPCLIENT] = new this.HttpClient(this.config.httpclient);
    }
    return this[HTTPCLIENT];
  }
 
  /**
   * core app have been loaded
   */
  async ready () {
    // do some things
  }
}
 
module.exports = BaseApp;