BAE上部署Ghost 0.5.1注意事项

BAE上部署Ghost可参考基本安装上述安装使用的是ghost0.4.7版本
在ghost 0.5 中为了解决测试时事件侦听器过多引发的警告,在注册single事件时,将代码由原先的

    process.on('SIGINT', function () {
         //...
            );
            process.exit(0);
        });

改为先移除所有的侦听器

    process.removeAllListeners('SIGINT').on('SIGINT', function () {
            //...
            );
            process.exit(0);
        });

在node 0.10.23版本下 对移除removeAllListeners的处理逻辑为

  listeners = this._events[type];
   
  if (typeof listeners === 'function') {
   // 如果该事件只有一个侦听器时
    this.removeListener(type, listeners);
  } else {
    while (listeners.length)
      this.removeListener(type, listeners[listeners.length - 1]);
  }

由于 ghost启动时 process的siging并未添加任何侦听器,所以其监听者队列为

listeners = this._events[siging] = undefined;

虽然node在0.10.23版本修复了这个bug新增了逻辑判断

if (typeof listeners === 'function') {
    this.removeListener(type, listeners);
  } else if (Array.isArray(listeners)) {
    // 只有存在监听队列时才执行下面的逻辑
    while (listeners.length)
      this.removeListener(type, listeners[listeners.length - 1]);
  }

遗憾的是,bae的node运行环境是 0.10.21,并未修复该bug.所以在ghost初始化时会引发 undefined has no property length 异常.为了解决这个问题,我们只能将初始化时的代码回滚为0.4.7版本,该改动在生产环境不会造成任何不良影响.
如果有人清楚bae 上更node运行环境的办法请告知
-------以下内容引用自玩转JAE------------

让 JAE 支持 Koa.js

其实就是让 JAE 支持 0.11.9 以上的 Node 版本,因为 Koa.js 使用了只有 0.11.9 以上版本 Node 的新特性 generator,以解决 callback hell 问题

JAE 提供的 Node 版本号为 0.10.15,显然是无法部署基于 Koa.js 框架的应用的。其实让 JAE 支持最新版本的 Node 也很简单,那就是自己提供最新版本的 Node ,Node.js 官网提供了编译好的各平台的二进制文件,而且除去 npm 就只有一个单个文件,部署非常方便,比如我下载了最新版本的 Node (v0.11.13) for linux-x64 ,解压出 Node 文件放在应用的 vendor 文件夹,然后修改 Procfile 文件为 web: ./vendor/node --harmony app.js ,然后像普通的 Node 应用一样部署即可


posted @ 2014-09-14 14:17  萝卜奸商  阅读(174)  评论(0编辑  收藏  举报