Beispiel #1
0
 $mountMiddlewares(app, items) {
   callback();
   items = antsort(items, { defaultLevel: 3 });
   items.forEach(item => {
     app.use(item.module);
   });
 }
Beispiel #2
0
function mountMiddlewares(server, items) {
  const sorted = antsort(items, { defaultLevel: 3 });
  for (const item of sorted) {
    logger.info('load middleware: %s, level: %s', item.name, item.level);
    server.use(item.module);
  }
}
Beispiel #3
0
  /**
   * 加载插件
   *
   * 插件是一个plover模块
   * plover模块是一个`package.json`中配置plover域的node模块
   * 插件要求plover域中配置属性`plugin: path`
   *
   * @param {PloverApplication} app - Plover应用对象
   */
  constructor(app) {
    let plugins = getEnablePlugins(app);
    plugins = antsort(plugins, { defaultLevel: 3 });
    logger.info('install plugins:\n%o', plugins.map(info => info.name));

    for (const info of plugins) {
      logger.info('startup plugin: %s', info.name);
      const path = Path.join(info.path, info.plugin);
      const fn = require(path);
      assert(typeof fn === 'function',
        'plugin module should be a function: ' + path);
      fn(app.proto);
    }
  }
Beispiel #4
0
  /**
   * 处理Plover模块渲染逻辑
   *
   * 一个请求对应一个Navigator对象
   * 由components/navigate构造,并调用navigate方法
   * 由于一个页面可能会有多个模块拼装而成
   * 所以会递归多次调用navigate方法,这发生在模板(通过app.view/app.control)中
   *
   * @param {PloverApplication} app   - Plover应用对象
   * @param {KoaContext}    ctx       - Koa上下文
   */
  constructor(app, ctx) {
    this.settings = app.settings;
    this.development = app.settings.development;

    this.app = app;
    this.ctx = ctx;

    this.moduleResolver = app.moduleResolver;

    // filters中的顺序可由level指定
    this.filters = app.filters.length ?
        antsort(app.filters, { defaultLevel: 3 }) : [];

    this.actionRunner = new ActionRunner(app, this);
    this.viewRender = new ViewRender(app, this);

    // 一个请求只对应于一个layout对象
    this[LAYOUT] = {
      enable: true,
      name: 'layouts:view',
      data: {}
    };
  }