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GJ,GAAO,IACT,EAAM,GAEI,IACR,GAAO,GAIX,KAAK,YAAY,MAAQ,EACzB,KAAK,QAAQ,KAAO,EAEhB,EAAM,EACR,IAAK,IAAI,KAAK,KAAK,OACjB,KAAK,OAAO,GAAK,SAAS,KAAK,OAAO,IAAM,IAAO,EAAI,IAI3D,KAAK,QAAQ,KAAwB,iBAAT,EAAoB,EAAO,GAEf,iBAA7B,KAAK,OAAO,eACrB,KAAK,OAAO,aAAe,IAGM,iBAAxB,KAAK,OAAO,SAAwB,KAAK,OAAO,QAAQ,OAAS,GAC1E,GAAG,UAAU,KAAK,OAAO,QAAS,GAAG,QAAQ,OAAQ,IACnD,GAAO,QAAQ,MAAM,EAAI,IAI7B,KAAK,gBAGL,KAAK,eACL,KAAK,OAAO,QACZ,KAAK,QAAQ,SAAW,CAAC,EAEzB,KAAK,oBAEL,KAAK,cAEL,IAAK,IAAI,EAAI,EAAG,EAAI,EAAK,IACvB,QAAQ,OAGV,OAAO,IAET,CAAO,GAAI,QAAQ,SAOjB,OALI,KAAK,OAAO,cACd,KAAK,QAAQ,aAGf,KAAK,OAAS,KAAK,IAAI,EAAM,GACtB,KAAK,MAEhB,CAEA,YAAI,GACF,OAAO,QAAQ,WAAa,QAAQ,QACtC,CAEA,aAAI,GACF,OAAO,QAAQ,WAAa,QAAQ,QACtC,CAEA,YAAI,GACF,OAAO,QAAQ,QACjB,EAIF,OAAO,QAAU","file":"/npm/titbit@25.2.0/lib/titbit.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/titbit@25.2.0/lib/titbit.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nconst process = require('node:process');\n\nconst versionCheck = require('./versionCheck.js');\nlet _vchk = versionCheck();\n\nif (_vchk.stat === false) {\n  console.error(_vchk.errmsg);\n  process.exit(1);\n}\n\nconst fs = require('node:fs');\nconst cluster = require('node:cluster');\nconst os = require('node:os');\nconst {spawn} = require('node:child_process');\nconst Bodyparser = require('./bodyparser.js');\nconst Middleware1 = require('./middleware1.js');\nconst Middleware2 = require('./middleware2.js');\nconst Router = require('./router.js');\nconst connfilter = require('./connfilter.js');\nconst Http1 = require('./http1.js');\nconst Httpt = require('./http2.js');\nconst Httpc = require('./httpc.js');\nconst loggermsg = require('./loggermsg.js');\nconst Monitor = require('./monitor.js');\nconst Strong = require('./strong.js');\nconst optionsCheck = require('./optionsCheck.js');\nconst Context1 = require('./context1.js');\nconst Context2 = require('./context2.js');\nconst helper = require('./helper.js');\n\nlet __instance__ = 0;\n\nlet _titbit_server_running = `\n:.:.:.:.:.:.titbit in service.:.:.:.:.:.:\n`;\n\nlet _titbit_home_page = `<!DOCTYPE html><html>\n<head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width\"></head>\n<body>\n  <div style=\"width:90%;margin:auto;margin-top:1rem;color:#4a4a4f;\">\n    <div style=\"text-align:center;\">\n      <h1>titbit</h1>\n      <br>\n      <p>功能强大、简洁高效的Web开发框架。</p>\n      <p>文档 & 仓库：\n        <a style=\"text-decoration:none;color:#345689;\" href=\"https://gitee.com/daoio/titbit\" target=_blank>\n          titbit</a></p>\n    </div>\n  </div>\n</body>\n</html>`;\n\nfunction sigExit() {\n    process.kill(0, 'SIGTERM');\n    \n    //防止有监听SIGTERM不退出的情况。\n    setTimeout(() => {\n      process.kill(0, 'SIGKILL');\n    }, 5);\n}\n\nfunction makeSubAppForGroup(app, grp_name) {\n  let makeOptions = (grp, opts) => {\n    if (!opts || typeof opts !== 'object') {\n      return {group: grp}\n    }\n\n    let options = {...opts}\n    \n    options.group = grp\n\n    return options\n  }\n\n  let subapp = {\n    /* middleware: (mids, options=null) => {\n      if (!Array.isArray(mids)) mids = [mids]\n\n      for (let m of mids) {\n        app.use(m, makeOptions(grp_name, options))\n      }\n\n      return subapp\n    }, */\n\n    pre: function (mid, options=null) {\n      app.pre(mid, makeOptions(grp_name, options))\n      return this\n    },\n\n    use: function (mid, options=null) {\n      app.use(mid, makeOptions(grp_name, options))\n      return this\n    }\n  }\n\n  Object.defineProperties(subapp, {\n    __mids__: {\n      enumerable: false,\n      writable: true,\n      value:[]\n    },\n    __prefix__: {\n      enumerable: false,\n      writable: true,\n      value: ''\n    },\n    __group__: {\n      enumerable: false,\n      writable: true,\n      value: ''\n    },\n  })\n\n  return subapp\n}\n\nclass Titbit {\n  /**\n   * @param {object} options 初始化选项，参考值如下：\n   * - debug 调试模式，默认为false\n   * - maxConn 最大连接数，使用daemon接口，则每个进程都可以最多处理maxConn限制数量，0表示不限制。\n   * - deny  {Array} IP字符串数组，表示要拒绝访问的IP。\n   * - maxIPRequest {number} 单个IP单元时间内最大访问次数。\n   * - unitTime {number} 单元时间，配合maxIPRequest，默认为1表示1秒钟清空一次。\n   * - maxIPCache {number} 最大IP缓存个数，配合限制IP访问次数使用，默认为50000。\n   * - allow   {Array} 限制IP请求次数的白名单。\n   * - useLimit {bool} 启用连接限制，用于限制请求的选项需要启用此选项才会生效。\n   * - timeout {number} 超时。\n   * - cert {string} 启用HTTPS要使用的证书文件路径。\n   * - key  {string} 启用HTTPS的密钥文件路径。\n   * - globalLog {bool} 启用全局日志。\n   * - maxBody {number} 表示POST/PUT提交表单的最大字节数，包括上传文件。\n   * - maxFiles {number} 最大上传文件数量，超过则不处理。\n   * - daemon {bool} 启用守护进程模式。\n   * - pidFile {string} 保存Master进程PID的文件路径。\n   * - logFile {string} 日志文件。\n   * - errorLogFile {string} 错误日志文件。\n   * - logType {string} 日志类型，支持stdio、file、self\n   * - logHandle {function} 自定义日志处理函数，接收参数为worker和msg（json格式的日志）\n   * - logHistory {number} 最大日志文件数量，默认为50。\n   * - server {object}  服务器选项，参考http2.createSecureServer\n   * - notFound {string} 404页面数据。\n   * - parseBody {bool} 自动解析上传文件数据，默认为true。\n   * - http2 {bool} 默认false。\n   * - allowHTTP1 {bool} 默认为false。\n   * - loadInfoFile {string} daemon为true，负载信息会输出到设置的文件，默认为空\n   * - memFactor {number} 控制内存最大使用量的系数，范围从 -0.45 ～ 0.45，会使用基本系数加上此值并乘以内存总量。默认值0.28。\n   *      RSS基本系数是0.52。不要设置的太低，提供比较低的值是为了测试使用。\n   * - maxUrlLength 最大URL长度，包括path和querystring\n   * - maxpool 请求上下文的最大缓存池数量。\n   * - loadMonitor true|false，表示是否启用负载监控功能，在daemon模式有效，默认为true。\n   * - monitorTimeSlice 子进程获取系统占用资源的定时器时间片，毫秒值，默认为500。\n   * - maxQuery 最大允许的querystring的参数，默认为12。\n   * - fastParseQuery 快速解析querystring，默认为false，会把多个重名的解析为数组，true表示快速解析，不允许重复的名字，否则仅第一个生效。\n   * - maxFormLength 在multipart/form-data类型提交数据时，单个form项的最大值，默认为1000000字节。\n   * - errorHandle 收集错误并处理的函数，默认是输出错误信息，接收参数为两个，第一个是错误信息，第二个是错误的名字描述。\n   * - ignoreSlash 忽略末尾的/，默认为true。\n   * - maxLoadRate 在自动创建子进程平衡负载模式，最大子进程负载率限制：25 ～ 98表示百分比。\n   * - streamTimeout http2Stream超时，若不设置，默认采用timeout的设置。\n   */\n  constructor(options={}) {\n    if (__instance__ > 0)\n      throw new Error('titbit遵循单例模式，不能构造多次。你可以在多进程或多线程中构造新的实例。');\n\n    __instance__ += 1;\n  \n    this.config = {\n      //此配置表示POST/PUT提交表单的最大字节数，也是上传文件的最大限制，\n      maxBody   : 50_000_000,\n      maxFiles      : 12,\n      daemon        : false, //开启守护进程\n  \n      //开启守护进程模式后，如果设置路径不为空字符串，则会把pid写入到此文件，可用于服务管理。\n      pidFile       : '',\n      logFile       : '',\n      errorLogFile  : '',\n  \n      //最大日志文件数量\n      logHistory    : 50,\n  \n      logMaxLines   : 20000,\n      \n      // stdio or file\n      logType     : 'stdio',\n  \n      //开启HTTPS\n      https       : false,\n  \n      http2       : false,\n  \n      allowHTTP1  : false,\n  \n      //HTTPS密钥和证书的路径\n      key   : '',\n      cert  : '',\n  \n      //服务器选项，参考http2.createSecureServer、tls.createServer\n      server : {\n        //TLS握手连接（HANDSHAKE）超时\n        handshakeTimeout: 9000\n      },\n  \n      //设置服务器超时，毫秒单位。\n      timeout   : 20000,\n  \n      debug     : false,\n      \n      notFound  : 'not found',\n      badRequest : 'bad request',\n      //展示负载信息，必须使用daemon接口\n      showLoadInfo  : true,\n      loadInfoType  : 'text', // text | json | orgjson | --null\n      loadInfoFile  : '',\n  \n      ignoreSlash: true,\n      parseBody: true,\n  \n      useLimit: false,\n  \n      //启用全局日志\n      globalLog: false,\n      logHandle : null,\n      realIP: false,\n  \n      //内存使用控制系数，-0.35 ~ 0.35\n      memFactor : 0.28,\n  \n      autoDecodeQuery : true,\n  \n      maxUrlLength: 1152,\n  \n      maxpool : 4096,\n  \n      //子进程汇报资源信息的定时器毫秒数。\n      monitorTimeSlice: 500,\n  \n      //querystring最大个数\n      maxQuery: 25,\n  \n      //快速解析querystring，多个同名的值会仅设置第一个，不会解析成数组。\n      fastParseQuery: false,\n  \n      strong : false,\n  \n      //在multipart格式中，限制单个表单项的最大长度。\n      maxFormLength: 1000000,\n  \n      //允许的最大表单键值个数。\n      maxFormKey: 100,\n  \n      errorHandle: (err, errname = '') => {\n        if (err) {\n          if (err.code === 'HPE_INVALID_EOF_STATE' || err.code === 'ERR_HTTP_REQUEST_TIMEOUT') {\n            return;\n          }\n        }\n  \n        this.config.debug && console.error(errname, err);\n      },\n  \n      //-1表示使用timeout的设置。\n      streamTimeout: -1,\n  \n      requestTimeout: 100000,\n  \n      maxLoadRate: 75\n    };\n  \n    this.whoami = 'titbit';\n  \n    this.limit = {\n      maxConn       : 2560,\n      deny          : null,\n      deny_type     : 's',\n      //每秒单个IP可以进行请求次数的上限，0表示不限制。\n      maxIPRequest  : 0,\n      unitTime      : 60_000,\n      maxIPCache    : 10_0000,\n      allow         : null,\n      allow_type    : 's',\n    };\n  \n    if (typeof options !== 'object') options = {};\n  \n    for(let k in options) {\n      switch (k) {\n        case 'maxConn':\n          optionsCheck(k, options[k], this.limit, {type: 'number', min: 0});\n          break;\n  \n        case 'deny':\n          optionsCheck(k, options[k], this.limit, {type: ['set', 'function']});\n          this.limit.deny_type = (typeof options[k] === 'function') ? 'f' : 's';\n          break;\n        \n        case 'maxIPRequest':\n          optionsCheck(k, options[k], this.limit, {type: 'number', min: 0});\n          break;\n  \n        case 'unitTime':\n          if (typeof options[k] === 'number' && options[k] >= 0.1 && options[k] <= 86400) {\n            this.limit.unitTime = parseInt(options[k] * 1000);\n          }\n          break;\n  \n        case 'maxIPCache':\n          optionsCheck(k, options[k], this.limit, {type: 'number', min: 1024});\n          break;\n        \n        case 'allow':\n          optionsCheck(k, options[k], this.limit, {type: ['set', 'function']});\n          this.limit.allow_type = (typeof options[k] === 'function') ? 'f' : 's';\n          break;\n  \n        case 'logHandle':\n        case 'errorHandle':\n          optionsCheck(k, options[k], this.config, {type: 'function'});\n          break;\n        \n        case 'logMaxLines':\n          optionsCheck(k, options[k], this.config, {type: 'number', min: 1, max: 5000000});\n          break;\n  \n        case 'memFactor':\n          optionsCheck(k, options[k], this.config, {type: 'number', min: -0.45, max: 0.45});\n          break;\n  \n        case 'maxUrlLength':\n          optionsCheck(k, options[k], this.config, {type: 'number', min: 1, max: 4096});\n          break;\n        \n        case 'maxpool':\n          optionsCheck(k, options[k], this.config, {type: 'number', min: 2, max: 50000});\n          break;\n  \n        case 'monitorTimeSlice':\n          optionsCheck(k, options[k], this.config, {type: 'number', min: 5, max: 5000});\n          break;\n  \n        case 'maxLoadRate':\n          optionsCheck(k, options[k], this.config, {type: 'number', min: 25, max: 98});\n          break;\n  \n        case 'maxFiles':\n        case 'maxBody':\n        case 'maxQuery':\n        case 'requestTimeout':\n        case 'timeout':\n        case 'streamTimeout':\n          optionsCheck(k, options[k], this.config, {type: 'number', min: 0});\n          break;\n  \n        case 'maxFormLength':\n        case 'maxFormKey':\n        case 'logHistory':\n          optionsCheck(k, options[k], this.config, {type: 'number', min: 1});\n          break;\n  \n        case 'logType':\n          optionsCheck(k, options[k], this.config, {list: ['stdio','file', '']});\n          break;\n        \n        case 'loadInfoType':\n          optionsCheck(k, options[k], this.config, {list: ['--null', 'text', 'json', 'orgjson']});\n          break;\n  \n        case 'loadMonitor':\n          this.config.showLoadInfo = !!options[k];\n          break;\n  \n        case 'showLoadInfo':\n        case 'daemon':\n        case 'debug':\n        case 'globalLog':\n        case 'ignoreSlash':\n        case 'parseBody':\n        case 'useLimit':\n        case 'http2':\n        case 'https':\n        case 'autoDecodeQuery':\n        case 'realIP':\n        case 'fastParseQuery':\n        case 'allowHTTP1':\n          this.config[k] = !!options[k]; break;\n  \n        case 'notFound':\n        case 'badRequest':\n        case 'logFile':\n        case 'errorLogFile':\n        case 'loadInfoFile':\n        case 'pidFile':\n          optionsCheck(k, options[k], this.config, {type: 'string'});\n          break;\n  \n        case 'strong':\n          this.config[k] = options[k]; break;\n  \n        default:\n          if (this.config[k] === undefined) {\n            setTimeout(() => {\n              console.error(`\\x1b[7m!!未知选项: ${k}\\n!!请查看文档使用正确的选项。\\n\\x1b[0m`);\n            }, 500);\n          }\n      }\n    }\n  \n    if (options.server && typeof options.server === 'object') {\n      for (let x in options.server) {\n        this.config.server[x] = options.server[x];\n      }\n    }\n  \n    if (options.key && options.cert) {\n      this.config.cert = options.cert;\n      this.config.key = options.key;\n      this.config.https = true;\n    } else if (this.config.server.SNICallback && typeof this.config.server.SNICallback === 'function') {\n      this.config.https = true;\n    }\n  \n    if (this.config.streamTimeout < 0) {\n      this.config.streamTimeout = this.config.timeout;\n    }\n  \n    //记录当前的运行情况\n    this.rundata = {\n      conn: 0,\n      platform: os.platform(),\n      host: '',\n      port: 0,\n      cpuLast: {user:0,system:0},\n      cpuTime: {user:0,system:0},\n      mem: {\n        rss: 0,\n        heapTotal: 0,\n        heapUsed: 0,\n        external: 0,\n        //rss + external\n        total: 0,\n        arrayBuffers: 0\n      },\n      cpus: 0\n    };\n    \n    /**\n     * 用于限制在daemon模式，子进程如果真的超出最大内存限制则会重启子进程。\n     * 因为RSS包括了Buffer的占用，所以maxrss包括Buffer默认的最大限制。\n     * Node.js 14+运行时堆内存限制已经突破了4G。\n     * Buffer的单个块上限也早就突破了2G限制。\n     * 注意：Node.js利用Buffer没有理论内存上限的限制。\n     * */\n    this.totalmem = os.totalmem();\n    this.topmem = 4345036800;\n  \n    if (this.topmem >= this.totalmem) {\n      this.topmem = parseInt(this.totalmem * 0.9);\n    }\n\n    this.secure = {\n      //而超过diemem则直接kill 这限制的是对heap的使用\n      //parseInt(this.topmem * (0.5 + this.config.memFactor) )\n      diemem : this.topmem,\n  \n      //parseInt(this.topmem * (0.5 + this.config.memFactor) )\n      maxmem : parseInt(this.topmem * (0.5 + this.config.memFactor)),\n  \n      maxrss : parseInt(this.totalmem * (0.52 + this.config.memFactor) )\n    };\n    \n    //运行时服务，需要在全局添加一些服务插件可以放在此处。\n    //如果需要把app相关配置信息，router等传递给请求上下文可以放在此处。\n    Object.defineProperty(this, 'service', {\n      enumerable: false,\n      writable: false,\n      configurable: false,\n      value: Object.create(null)\n    });\n  \n    this.bodyparser = new Bodyparser({\n      maxFormKey: this.config.maxFormKey,\n      maxFiles: this.config.maxFiles,\n      maxFormLength: this.config.maxFormLength\n    });\n  \n    this.router = new Router(this.config);\n    this.router.__subapp__ = makeSubAppForGroup.bind(this,this);\n  \n    //连接过滤和计数以及超时控制。\n    this.connfilter = connfilter;\n  \n    if (this.config.http2) {\n      if (this.config.allowHTTP1) {\n        this.config.server.allowHTTP1 = true;\n      } else if (this.config.server.allowHTTP1) {\n        this.config.allowHTTP1 = true;\n      }\n    }\n  \n    if (this.config.http2 && !this.config.allowHTTP1) {\n      this.midware = new Middleware2(this.config);\n    } else {\n      this.midware = new Middleware1(this.config);\n    }\n  \n    this.eventTable = {};\n    this.server = {};\n    this.__pre_mids__ = [];\n    let opts = {\n      config: this.config,\n      events: this.eventTable,\n      router: this.router,\n      midware: this.midware,\n      service: this.service,\n      isWorker: this.isWorker,\n    };\n  \n    if (this.config.http2 && !this.config.allowHTTP1) {\n      this.httpServ = new Httpt(opts);\n    } else {\n      this.httpServ = new Http1(opts);\n      if (this.config.http2 && this.config.allowHTTP1) {\n        let hc = new Httpc();\n        hc.init(this);\n      }\n    }\n  \n    this.logger = null;\n    this.monitor = null;\n  \n    this.__init__();\n  }\n\n  __init__() {\n    if (this.__init_flag__) return false;\n    //workers记录了在cluster模式，每个worker的启动时间，这可以在disconnect事件中检测。\n    Object.defineProperties(this, {\n      workers: {\n        enumerable: false,\n        configurable: false,\n        writable: false,\n        value: Object.create(null)\n      },\n      workerCount: {\n        enumerable: false,\n        configurable: false,\n        writable: false,\n        value: {\n          total : 0,\n          cur : 0,\n          max : 0,\n          canAutoFork: true,\n        }\n      },\n  \n      msgEvent: {\n        enumerable: false,\n        configurable: false,\n        writable: false,\n        value: Object.create(null)\n      }\n    });\n  \n    //如果worker运行在很短时间内退出说明可能存在问题，这时候则终止master进程并立即给出错误信息。\n    //注意这是在运行开始就要判断并解决的问题。设置值最好不低于100，也不要太高。\n    this.workerErrorTime = 500;\n    this.errorBreakCount = 0;\n    this.keepWorkersTimer = null;\n  \n    if (this.config.globalLog) {\n      this.logger = new loggermsg(this.config);\n      if (this.isMaster) {\n        this.logger._checkBeforeInit();\n        this.logger.init();\n        this.setMsgEvent('_log', this.logger.msgEvent());\n      }\n    }\n  \n    if (this.config.showLoadInfo) {\n      this.monitor = new Monitor({\n        config : this.config,\n        secure : this.secure,\n        workers : this.workers,\n        rundata : this.rundata,\n        workerCount : this.workerCount\n      });\n  \n      if (this.isMaster) {\n        this.setMsgEvent('_load', this.monitor.msgEvent());\n      }\n    }\n  \n    if (this.config.strong === true) {\n      this.config.strong = {}\n    }\n\n    this.strong = null;\n    if (this.config.strong && this.config.strong.toString() === '[object Object]') {\n      this.strong = new Strong(this.config.strong);\n      this.strong.init();\n    }\n\n    this.helper = helper;\n    this.ext = helper;\n  \n    this.context = (type = '') => {\n      if (type === 1 || type === '1') return new Context1();\n      else if (type === 2 || type === '2') return new Context2();\n      return (this.config.http2 && !this.config.allowHTTP1) ? new Context2() : new Context1();\n    };\n  \n    this.initMsgEvent();\n    this.__init_flag__ = true;\n  }\n\n  /**\n   * \n   * @param {string} path 路由字符串\n   * @param {function} cb 回调函数\n   * @param {object|string} options 选项\n   */\n  get(path, cb, options='') {\n    return this.router.get(path, cb, options)\n  }\n\n  /**\n   * \n   * @param {string} path 路由字符串\n   * @param {function} cb 回调函数\n   * @param {object|string} options 选项\n   */\n  post(path, cb, options='') {\n    return this.router.post(path, cb, options)\n  }\n\n  /**\n   * \n   * @param {string} path 路由字符串\n   * @param {function} cb 回调函数\n   * @param {object|string} options 选项\n   */\n  put(path, cb, options='') {\n    return this.router.put(path, cb, options)\n  }\n\n  /**\n   * \n   * @param {string} path 路由字符串\n   * @param {function} cb 回调函数\n   * @param {object|string} options 选项\n   */\n  delete(path, cb, options='') {\n    return this.router.delete(path, cb, options)\n  }\n\n  /**\n   * \n   * @param {string} path 路由字符串\n   * @param {function} cb 回调函数\n   * @param {object|string} options 选项\n   */\n  options(path, cb, options='') {\n    return this.router.options(path, cb, options)\n  }\n\n  /**\n   * \n   * @param {string} path 路由字符串\n   * @param {function} cb 回调函数\n   * @param {object|string} options 选项\n   */\n  patch(path, cb, options='') {\n    return this.router.patch(path, cb, options)\n  }\n\n  /**\n   * \n   * @param {string} path 路由字符串\n   * @param {function} cb 回调函数\n   * @param {object|string} options 选项\n   */\n  head(path, cb, options='') {\n    return this.router.head(path, cb, options)\n  }\n\n  /**\n   * \n   * @param {string} path 路由字符串\n   * @param {function} cb 回调函数\n   * @param {object|string} options 选项\n   */\n  trace(path, cb, options='') {\n    return this.router.trace(path, cb, options)\n  }\n\n  /**\n   * \n   * @param {string} grp_name 路由分组名称\n   * @param {function} cb 回调函数\n   * @param {boolean} prefix 是否作为前缀路经，默认为true，当检测到路由是合法的模式会自动设置为前缀路径\n   */\n  group(grp_name, cb, prefix=true) {\n    ;(typeof cb === 'boolean') && (prefix = cb);\n    return this.router.group(grp_name, cb, prefix)\n  }\n\n  /**\n   * \n   * @param {Array} mids \n   * @returns {object} - 属性值group函数\n   */\n  middleware(mids, options=null) {\n    let submid = {\n      group: (grp_name, cb, prefix=true) => {\n        ;(typeof cb === 'boolean') && (prefix = cb);\n\n        let subapp = makeSubAppForGroup(this, grp_name);\n        //如果数组的一个元素还是数组，那么第一个是中间件，第二个是选项\n        subapp.__mids__.push({\n          mids: mids,\n          options: options\n        });\n\n        subapp.__group__ = grp_name.trim();\n\n        return this.router.__group__(grp_name, cb, subapp, prefix, this.router.__subapp__);\n      }\n    }\n\n    return submid;\n  }\n\n  /**\n   * @param {array} marr method数组，示例['GET','HEAD']。\n   * @param {string} path 路由字符串。 \n   * @param {function} callback 请求处理回调函数，必须是async声明。\n   * @param {string} name 请求命名，默认为空字符串，可以不写。\n   */\n  map(marr, path, callback, name = '') {\n    return this.router.map(marr, name, callback, name);\n  }\n\n  /**\n   * @param {string} path 路由字符串。 \n   * @param {function} callback 请求处理回调函数，必须是async声明。\n   * @param {string} name 请求命名，默认为空字符串，可以不写。\n   */\n  any(path, callback, name = '') {\n    return this.router.any(name, callback, name);\n  }\n\n  initMsgEvent() {\n    this.setMsgEvent('_eaddr', (w, msg, handle = undefined) => {\n        let errmsg = '\\x1b[1;35m端口已被使用，请先停止正在运行的进程。\\n在Linux/Unix上，可通过\\n\\t'\n          +'ps -e -o user,pid,ppid,comm,args | grep node | grep -v grep\\n'\n          +' 或\\n\\tss -utlp\\n查看相关进程。在Windows上通过任务管理器查找并结束相关进程。\\x1b[0m';\n  \n        console.error(errmsg);\n        sigExit();\n    }, 'once');\n  \n    this.setMsgEvent('_route-table', (w, msg, handle = undefined) => {\n        console.log(msg.route);\n        console.log('PID:', process.pid, msg.listen, msg.protocol);\n        console.log(_titbit_server_running);\n    }, 'once');\n  \n    this.setMsgEvent('_server-error', (w, msg, handle=undefined) => {\n        let hintText = '出现这种情况说明遇到了错误情况不得不终止服务，请根据错误提示信息排查解决。';\n        console.error(`\\x1b[1;35m${msg.message}\\n${hintText}\\x1b[0m`);\n        sigExit();\n    }, 'once');\n  \n  }\n  \n  /**\n   * @param {string} - evt\n   * @param {function} - callback\n   * */\n  on(evt, callback) {\n    if (evt === 'requestError') {\n      if (typeof callback === 'function') {\n        this.httpServ.requestError = callback;\n      }\n      return;\n    }\n    \n    if (!this.eventTable[evt]) {\n      this.eventTable[evt] = [ callback ];\n    } else {\n      this.eventTable[evt].push(callback);\n    }\n  }\n  \n  /**\n   * @param {function} midcall \n   * @param {object} options 支持选项：group、name。 \n   */\n  add(midcall, options={}) {\n    this.midware.add(midcall, options);\n    return this;\n  }\n  \n  /**\n   * @param {function} midcall \n   * @param {object} options 支持选项：group、name、pre。\n   */\n  use(midcall, options={}) {\n    if (typeof options === 'object' && options.pre !== undefined) {\n      if (options.pre) {\n        return this.pre(midcall, options);\n      }\n    }\n  \n    this.midware.addCache(midcall, options);\n    return this;\n  }\n  \n  /**\n   * @param {function} midcall \n   * @param {object} options 支持选项：group、name。\n   */\n  pre(midcall, options={}) {\n    this.__pre_mids__.push({\n      callback: midcall,\n      options: options\n    });\n  \n    return this;\n  }\n  \n  /**\n   * \n   * @param {string|symbol} key\n   * @param {string|object|array|boolean|number|function} serv \n   */\n  addService(key, serv) {\n    if (typeof key === 'object') {\n      for (let k in key) {\n        this.service[k] = key[k];\n      }\n      return this;\n    }\n  \n    this.service[key] = serv;\n    return this;\n  }\n  \n  getService(key) {\n    return this.service[key] || null;\n  }\n  \n  clearService() {\n    for (let k in this.service) delete this.service[k];\n  }\n  \n  /** \n   * 根据配置情况确定运行HTTP/1.1还是HTTP/2\n   * @param {number} port 端口号\n   * @param {string} host IP地址，可以是IPv4或IPv6\n   * 0.0.0.0 对应使用IPv6则是::\n  */\n  run(port=2368, host='0.0.0.0') {\n    if (typeof port === 'object') {\n      if (port.host && typeof port.host === 'string') host = port.host;\n      if (port.port && typeof port.port === 'number' && port.port > 0 && port.port <= 65535) port = port.port;\n    }\n\n    if (this.config.server.SNICallback && typeof this.config.server.SNICallback === 'function' && !this.config.https) {\n      this.config.https = true;\n    }\n  \n    this.router.argsRouteSort();\n  \n    this.rundata.host = (typeof port == 'number' ? host : '');\n    this.rundata.port = port;\n  \n    //如果没有添加路由则添加默认路由\n    if (this.router.count === 0) {\n      this.router.get('/*', async c => {\n        c.setHeader('content-type', 'text/html; charset=utf-8').send(_titbit_home_page)\n      })\n    }\n  \n    //如果发现更改了service指向，则让this.httpServ.service重新指向this.service。\n    if (this.service !== this.httpServ.service) {\n      this.httpServ.service = this.service;\n    }\n  \n    this.midware.addFromCache();\n  \n    this.config.parseBody && this.add(this.bodyparser);\n  \n    this.add(this.httpServ);\n  \n    let m = null;\n    while((m = this.__pre_mids__.pop()) !== undefined) {\n      this.add(m.callback, m.options);\n    }\n    \n    //必须放在最后，用于返回最终数据。\n    this.midware.addFinal();\n  \n    if (this.config.useLimit) {\n      let connlimit = new this.connfilter(this.limit, this.rundata);\n      this.on('connection', connlimit.callback);\n    } else {\n      this.on('connection', (sock) => {\n        this.rundata.conn++;\n        sock.on('close', () => {\n          this.rundata.conn--;\n        });\n  \n      });\n    }\n    \n    /**\n     * 输出路由表，如果是启用了cluster，则通过发送消息的方式让master进程输出。\n     * */\n    if (this.config.debug) {\n      if (typeof port === 'string' && port.indexOf('.sock') > 0) {\n        host = '';\n      }\n  \n      let is_https = this.config.https;\n  \n      let protocol = this.config.http2\n                      ? ('http2' + (is_https ? '[https]' : ''))\n                      : (is_https ? 'https' : 'http');\n  \n      if (cluster.isMaster) { \n        this.router.printTable();\n        console.log(`PID: ${process.pid}, Listen ${host}:${port}, Protocol: ${protocol}`);\n        console.log(_titbit_server_running);\n      } else if (process.send && typeof process.send === 'function') {\n        process.send({type:'_route-table', \n          route: this.router.getTable(),\n          listen: `Listen: ${host}${host.length > 0 ? ':' : ''}${port}, `,\n          protocol: `Protocol: ${protocol}`\n        });\n      }\n    }\n  \n    this.server = this.httpServ.run(port, host);\n    return this.server;\n  }\n  //run end\n\n  /**\n   * @param {string} evt\n   * @param {function} callback\n   * @param {string} mode always | once，默认always。\n   * */\n  setMsgEvent(evt, callback, mode='always') {\n    if (cluster.isWorker) {\n      return;\n    }\n\n    if (typeof callback !== 'function') {\n      console.error('setMsgEvent: callback not a function');\n      return false;\n    }\n\n    this.msgEvent[evt] = {\n      count: 0,\n      mode: mode,\n      callback: callback\n    };\n    return true;\n  }\n\n  getMsgEvent(evt) {\n    if (this.msgEvent[evt]) return this.msgEvent[evt];\n    return null;\n  }\n\n  removeMsgEvent(evt) {\n    if (this.msgEvent[evt]) {\n      let e = this.msgEvent[evt];\n      delete this.msgEvent[evt];\n      return e;\n    }\n\n    return false;\n  }\n\n  /** \n   * worker用于快速发送消息给master进程。\n   * @param {string} evtname 要发送消息的事件名称。\n   * @param {string|object} msg 要发送的消息。\n   * */\n  send(evtname, msg, handle=undefined) {\n    if (!cluster.isWorker || !process.send || typeof process.send !== 'function') return;\n\n    if (!msg) return;\n\n    let typn = typeof msg;\n\n    if (typn === 'string' || typn === 'number') msg = {msg: msg};\n\n    msg.type = evtname;\n\n    process.send(msg, handle);\n  }\n\n  workerMsg(callback) {\n    if (cluster.isWorker && callback && typeof callback === 'function') {\n      process.on('message', callback);\n    }\n  }\n\n  daemonMessage() {\n    if (cluster.isWorker) {\n      return;\n    }\n\n    let self = this;\n    for (let k in this.msgEvent) {\n      this.msgEvent[k].count = 0;\n    }\n\n    cluster.on('message', (worker, msg, handle) => {\n      try {\n        if (typeof msg === 'object' && msg.type !== undefined) {\n          if (self.msgEvent[msg.type] === undefined) {\n            return;\n          }\n          let devt = self.msgEvent[msg.type];\n          if (devt.mode === 'once' && devt.count > 0) {\n            return;\n          }\n\n          if (devt.count < 30000000000) {\n            devt.count += 1;\n          }\n          \n          devt.callback(worker, msg, handle);\n        }\n\n      } catch (err) {\n        self.config.debug && console.error(err);\n      }\n    });\n  }\n\n  autoWorker(max) {\n    if (typeof max === 'number' && max > 0) {\n      this.workerCount.max = max;\n    } else {\n      throw new Error('autoWorker参数必须是一个大于0的数字，表示最大允许创建多少个子进程处理请求。');\n    }\n  }\n\n  /**\n   * 调度类型，默认不做任何设置，采用Node.js cluster模块的默认设置。\n   * @param {string} sch \n   */\n  sched(sch = '') {\n    if (sch === 'rr') {\n      cluster.schedulingPolicy = cluster.SCHED_RR;\n    } else if (sch === 'none') {\n      cluster.schedulingPolicy = cluster.SCHED_NONE;\n    } else {\n      return cluster.schedulingPolicy;\n    }\n  }\n\n  _checkDaemonArgs() {\n    if (process.argv.indexOf('--daemon') > 0) {\n    } else if (this.config.daemon) {\n      let args = process.argv.slice(1);\n      args.push('--daemon');\n\n      const serv = spawn(process.argv[0], args, {\n        detached: true,\n        stdio: ['ignore', 1, 2]\n      });\n\n      serv.unref();\n      process.exit(0);\n    }\n  }\n\n  workerEventHandle() {\n    cluster.on('listening', (worker, addr) => {\n      this.workerCount.canAutoFork = true;\n      this.workerCount.cur += 1;\n\n      let onerr = err => {\n        this.config.errorHandle(err, '--ERR-WORKER--');\n      };\n\n      worker.on('error', onerr);\n      worker.process.on('error', onerr);\n\n      this.workers[ worker.id ] = {\n        startTime : Date.now(),\n        address : addr,\n        id : worker.id,\n        pid : worker.process.pid,\n        conn: 0,\n        mem: {\n          rss : 0,\n          heapTotal: 0,\n          heapUsed: 0,\n          external: 0,\n          total: 0\n        },\n        cpu: {user:0, system:0},\n        cputm : 1000\n      };\n      \n    });\n\n    let exitTip = () => {\n      setTimeout(() => {\n        let errmsg = `worker进程在限制的最短时间内(${this.workerErrorTime}ms)退出，请检测代码是否存在错误。`;\n        console.error(errmsg);\n        process.kill(0, 'SIGTERM');\n      }, 15);\n    };\n\n    cluster.on('disconnect', worker => {\n      worker.kill('SIGTERM');\n    });\n\n    cluster.on('exit', (worker, code, signal) => {\n      this.workerCount.canAutoFork = true;\n      this.workerCount.cur -= 1;\n      let w = this.workers[worker.id];\n      if (w) {\n        let tm = Date.now();\n        if (tm - w.startTime <= this.workerErrorTime && this.errorBreakCount <= 0 && code) {\n          exitTip();\n        } else {\n          delete this.workers[w.id];\n        }\n        this.errorBreakCount = 1;\n      } else {\n        exitTip();\n      }\n    });\n\n  }\n\n  keepWorkers() {\n    let keepworkers = () => {\n      let num_dis = this.workerCount.total - Object.keys(cluster.workers).length;\n\n      if (num_dis <= 0) return;\n\n      for (let i = 0; i < num_dis; i++) {\n        cluster.fork();\n      }\n    };\n\n    process.on('SIGCHLD', (sig) => {\n      if (this.workerCount.cur >= this.workerCount.total) {\n        return;\n      }\n\n      cluster.fork();\n\n      //测试kill多个子进程会有信号丢失的情况，设置定时器做最后的检测。\n      if (this.keepWorkersTimer === null) {\n        this.keepWorkersTimer = setTimeout (() => {\n          this.keepWorkersTimer = null;\n          keepworkers();\n        }, 2000);\n      }\n\n    });\n\n    if (process.platform === 'win32') {\n      setInterval(() => {\n        keepworkers();\n      }, 1024);\n    }\n\n  }\n\n  /**\n   * 这个函数是可以用于运维部署，此函数默认会根据CPU核数创建对应的子进程处理请求。\n   * @param {number} port 端口号\n   * @param {string} IP地址，IPv4或IPv6，如果检测为数字，则会把数字赋值给num。\n   * @param {number} num，要创建的子进程数量，0表示自动，这时候根据CPU核心数量创建。\n  */\n  daemon(port=2368, host='0.0.0.0', num=0) {\n    if (typeof host === 'number') {\n      num = host;\n      host = '0.0.0.0';\n    }\n    \n    if (typeof port === 'object') {\n      if (port.host && typeof port.host === 'string') host = port.host;\n      if (port.worker && typeof port.worker === 'number') num = port.worker;\n      if (port.port && typeof port.port === 'number' && port.port > 0 && port.port <= 65535) port = port.port;\n    }\n\n    //确保自动创建的worker在终止时不会误认为是系统错误。\n    setTimeout(() => {\n      this.errorBreakCount += 1;\n    }, this.workerErrorTime + 120);\n\n    this._checkDaemonArgs();\n    \n    if (cluster.isMaster) {\n      let osCPUS = os.cpus().length;\n      if (num > (osCPUS * 2) ) {\n        num = 0;\n      }\n\n      if (num <= 0) {\n        num = osCPUS;\n        //如果CPU核心数超过2个，则使用核心数-1的子进程处理请求。\n        if (num > 2) {\n          num -= 1;\n        }\n      }\n\n      this.workerCount.total = num;\n      this.rundata.port = port;\n      //根据num设定secure的内存限制。\n      if (num > 1) {\n        for (let k in this.secure) {\n          this.secure[k] = parseInt(this.secure[k] * (0.45 + 1 / num));\n        }\n      }\n\n      this.rundata.host = (typeof port === 'number' ? host : '');\n\n      if (typeof this.config.loadInfoFile !== 'string') {\n        this.config.loadInfoFile = '';\n      }\n\n      if (typeof this.config.pidFile === 'string' && this.config.pidFile.length > 0) {\n        fs.writeFile(this.config.pidFile, `${process.pid}`, (err) => {\n          err && console.error(err);\n        });\n      }\n\n      this.daemonMessage();\n\n      //clear router and service\n      this.clearService();\n      this.router.clear();\n      this.midware.midGroup = {};\n\n      this.workerEventHandle();\n\n      this.keepWorkers();\n\n      for (let i = 0; i < num; i++) {\n        cluster.fork();\n      }\n\n      return this;\n\n    } else if (cluster.isWorker) {\n\n      if (this.config.showLoadInfo) {\n        this.monitor.workerSend();\n      }\n\n      this.server = this.run(port, host);\n      return this.server;\n    }\n  }\n\n  get isMaster() {\n    return cluster.isPrimary || cluster.isMaster;\n  }\n\n  get isPrimary() {\n    return cluster.isPrimary || cluster.isMaster;\n  }\n\n  get isWorker() {\n    return cluster.isWorker;\n  }\n\n}\n\nmodule.exports = Titbit;\n"]}