OpenShift无法使用某些Node.js依赖项(Koa) [英] OpenShift not working with certain Nodejs dependencies (Koa)
问题描述
我已经检查了如何在Openshift中设置KoaJS ,仍然无法正常工作.
这是我的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?
快速部署0.12
https://hub.openshift.com/quickstarts/128 -node-js-0-12
对于希望委托nodejs 0.12
的人,请使用上面的链接,其中有一个按钮Deploy
.
0.12.2
要部署特定版本0.12.2
,请从https://github.com/ryanj/nodejs-custom-version-openshift
复制目录.openshift
,并覆盖您当前的项目.openshift
目录(我假设您使用的是创建应用程序时创建的OpenShifts git). /p>
导航到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
-和谐标志?
如 Node.js中可用的ECMAScript 6功能中所述的0.12
-某些功能仍需要和谐标记.这意味着也将它添加到您的package.json file
中,请看我的问题以查看示例.
I've checked out How to setup KoaJS in Openshift and it's still not working.
Here is a part of my package.json
file:
"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"
And then to my app.js
file.
This code works:
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+'/');
This does not work:
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+'/');
As you can see the only difference is that I have uncommented two lines.
Error:
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
Error logs on OpenShift state this:
...
.../app-root/runtime/repo/node_modules/koa/lib/application.js:179
function *respond(next) {
^
SyntaxError: Unexpected token *
...
A big duh.
console.log(process.versions);
reveals that I am using node 0.10.25
, even though I stated in package.json
that I wish to use >= 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' }
What is causing OpenShift to not use 0.12.2?
Quick deploy 0.12
https://hub.openshift.com/quickstarts/128-node-js-0-12
For people that whishes to deplot nodejs 0.12
use the link above, there's a button Deploy
.
0.12.2
To deploy the specific version 0.12.2
copy the directory .openshift
from https://github.com/ryanj/nodejs-custom-version-openshift
and overwrite your current projects .openshift
directory (I am presuming you are using OpenShifts git that was created when the app was created).
Navigate your way to your-project/.openshift/markers/
and open the file NODEJS_VERSION
and add 0.12.2
at the bottom. My file looks as so:
# 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
Then upload your project via git to OpenShift (be in your project root directory).
git add -A .
git commit -a -m "replaced .openshift directory"
git push
--harmony flag?
as stated in ECMAScript 6 features available in Node.js 0.12 --harmony flag is still needed for certain functions.
This means adding it too your package.json file
, look at my question to see an example.
这篇关于OpenShift无法使用某些Node.js依赖项(Koa)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!