OpenShift无法使用某些Nodejs依赖项(Koa)

时间:2015-04-24 12:58:50

标签: node.js openshift koa

我已经查看了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?

1 个答案:

答案 0 :(得分:1)

快速部署0.12

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

对于那些与deplot nodejs 0.12进行联系的人使用上面的链接,会出现一个按钮Deploy

0.12.2

部署特定版本0.12.2.openshift复制目录https://github.com/ryanj/nodejs-custom-version-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中所述 - 某些功能仍需要和声标志。

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