• app.use源码


    
    
      const isGeneratorFunction = require('is-generator-function');
      const debug = require('debug')('koa:application');
     /**
       * Use the given middleware `fn`.
       *
       * Old-style middleware will be converted.
       *
       * @param {Function} fn
       * @return {Application} self
       * @api public
       */
    
      use(fn) {
        if (typeof fn !== 'function') throw new TypeError('middleware must be a function!');
        if (isGeneratorFunction(fn)) { //代码转换用的
          deprecate('Support for generators will be removed in v3. ' +
                    'See the documentation for examples of how to convert old middleware ' +
                    'https://github.com/koajs/koa/blob/master/docs/migration.md');
          fn = convert(fn);
        }
        debug('use %s', fn._name || fn.name || '-');
        this.middleware.push(fn);  //最开始初始化会创建中间件空数组 ,其实use就是放到middleware数组中
        return this;
      }

  • 相关阅读:
    swarm集群搭建 及集群维护操作
    zabbix 告警说明
    yum 下载安装包
    mongdb常见操作
    cloudera5.16.1 离线安装
    centos7 安装hadoop-3.2.1
    rpcbind 启动报错
    ingress-nginx 安装
    Dubbo学习
    mybatis防止SQL注入
  • 原文地址:https://www.cnblogs.com/TTblog5/p/13097259.html
Copyright © 2020-2023  润新知