【问题标题】:OpenShift not working with certain Nodejs dependencies (Koa)OpenShift 不适用于某些 Nodejs 依赖项 (Koa)
【发布时间】:2015-07-03 02:21:51
【问题描述】:

我已经检查了How to setup KoaJS in Openshift,但它仍然无法正常工作。

这是我的package.json 文件的一部分:

  "engines": {
    "node": ">= 0.12.0",
    "npm": ">= 1.0.0"
  },

  "dependencies": {
    "co-busboy": "^1.3.0",
    "forever": "^0.14.1",
    "fs": "0.0.2",
    "koa": "^0.18.1",
    "koa-logger": "^1.2.2",
    "koa-router": "^4.2.0",
    "koa-static": "^1.4.9",
    "path": "^0.11.14"
    },
  "devDependencies": {},
  "bundleDependencies": [], 
  "private": true,
  "main": "--harmony app.js"

然后转到我的app.js 文件。

此代码有效:

var http = require('http');
//var koa = require('koa');
//var app = koa();

var ip = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1',
    port = process.env.OPENSHIFT_NODEJS_PORT || '8080';

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(port, ip);
console.log('Server running at http://'+ip+':'+port+'/');

这不起作用:

var http = require('http');
var koa = require('koa');
var app = koa();

var ip = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1',
    port = process.env.OPENSHIFT_NODEJS_PORT || '8080';

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(port, ip);
console.log('Server running at http://'+ip+':'+port+'/');

如您所见,唯一的区别是我取消了两行注释。

错误:

Service Temporarily Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

Apache/2.2.15 (Red Hat) Server at fela-basickarl.rhcloud.com Port 80

OpenShift 上的错误日志表明:

...
.../app-root/runtime/repo/node_modules/koa/lib/application.js:179
function *respond(next) {
         ^
SyntaxError: Unexpected token *
...

一个大废话。

console.log(process.versions); 表明我正在使用节点0.10.25,尽管我在package.json 中声明我希望使用>= 0.12.0

{ http_parser: '2.0',
  node: '0.10.25',
  v8: '3.14.5.10',
  ares: '1.9.1',
  uv: '0.10.23',
  zlib: '1.2.3',
  modules: '11',
  openssl: '1.0.0-fips' }

是什么导致 OpenShift 不使用 0.12.2?

【问题讨论】:

    标签: node.js openshift koa


    【解决方案1】:

    快速部署 0.12

    https://hub.openshift.com/quickstarts/128-node-js-0-12

    对于希望 deplot nodejs 0.12 的人使用上面的链接,有一个按钮 Deploy

    0.12.2

    要部署特定版本0.12.2,从https://github.com/ryanj/nodejs-custom-version-openshift 复制目录.openshift 并覆盖您当前的项目.openshift 目录(我假设您使用的是在创建应用程序时创建的OpenShifts git)。

    导航到your-project/.openshift/markers/ 并打开文件NODEJS_VERSION 并在底部添加0.12.2。我的文件如下所示:

    #  Uncomment one of the version lines to select the node version to use.
    #  The last "non-blank" version line is the one picked up by the code in
    #  .openshift/lib/utils
    #  Default: 0.10.25
    #
    #  0.8.24
    #  0.9.1
    #  0.10.25
    #  0.11.11
    #  0.10.25
    0.12.2
    

    然后通过 git 将您的项目上传到 OpenShift(在您的项目根目录中)。

    git add -A .
    git commit -a -m "replaced .openshift directory"
    git push
    

    --和谐标志?

    ECMAScript 6 features available in Node.js 0.12 中所述,某些功能仍需要 --harmony 标志。

    这意味着也将其添加到您的package.json file,请查看我的问题以查看示例。

    【讨论】:

      猜你喜欢
      • 2023-04-04
      • 2018-04-13
      • 1970-01-01
      • 1970-01-01
      • 2017-05-13
      • 2015-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多