简体   繁体   English

如何在Openshift中设置KoaJS

[英]How to setup KoaJS in Openshift

I've been following the example on how to enable custom node version in openshif ( http://www.zev23.com/2014/04/openshift-harmony-nodejs.html ) so when I ssh to the application I can see the node version(0.11.14) installed but the when I look at the logs it says app.use(function *(){ ... SyntaxError: Unexpected token * and I'm getting a 503 error. 我一直在关注如何在openshif( http://www.zev23.com/2014/04/openshift-harmony-nodejs.html )中启用自定义节点版本的示例,因此当我SSH到应用程序时,我可以看到节点版本(0.11.14)已安装,但是当我查看日志时显示为app.use(function *(){ ... app.use(function *(){错误SyntaxError: Unexpected token *并且出现503错误。

here's my server.js file: 这是我的server.js文件:

var koa = require('koa');
var app = module.exports = koa();

app.use(function *(){
  this.body = 'Hello World';
});

var ipaddress = process.env.OPENSHIFT_INTERNAL_IP || process.env.OPENSHIFT_NODEJS_IP;
var port = process.env.OPENSHIFT_INTERNAL_PORT || process.env.OPENSHIFT_NODEJS_PORT || 8080;
if (typeof ipaddress === "undefined") {
   //  Log errors on OpenShift but continue w/ 127.0.0.1 - this
   //  allows us to run/test the app locally.
   console.warn('No OPENSHIFT_NODEJS_IP var, using 127.0.0.1');
   ipaddress = "127.0.0.1";
};
if (!module.parent) app.listen(port, ipaddress);

I've also added 0.11.14 in the NODEJS_VERSION inside 我还在NODEJS_VERSION中添加了NODEJS_VERSION

__ UPDATE __ __更新__

I've check the server using ssh it says node 0.11.14 but when I added these lines( see below) before my actual web application starts it seams like it's running on node 0.10.25 and the path that was set in the .bash_profile is not the one being use in the path. 我已经使用ssh检查了服务器,它说的是节点0.11.14,但是当我在实际的Web应用程序启动之前添加这些行(请参阅下文)时,就好像它在节点0.10.25上运行并且在.bash_profile中设置的路径一样不是在路径中使用的那个。

var ipaddress = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
console.log(ipaddress, port);
console.log(process.versions);
console.log(process.env.PATH);

Is there a way to configure the PATH just before the actual application starts so it will use 0.11.14 instead of 0.10.25 有没有一种方法可以在实际应用程序启动之前配置PATH,因此它将使用0.11.14而不是0.10.25

Thanks in advance guys 在此先感谢大家

I've followed the instruction in https://github.com/ramr/nodejs-custom-version-openshift and everything is now working. 我已经按照https://github.com/ramr/nodejs-custom-version-openshift中的说明进行了操作,现在一切正常。 Just added main: --harmony server.js in package.json. 刚在package.json中添加了main: --harmony server.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM