[英]NODE.JS - OpenShift 503 Service is Temporarily Unavilable: Server.js and Package.json files are fine
Project running on a Node.js Server: 在Node.js服务器上运行的项目:
I'm going crazy over here. 我在这里疯了。 I can't figure out why I am getting a 503 error when I have done exactly what Open Shift instructs to do. 我完全不知道Open Shift指示要做什么,我无法弄清楚为什么我会收到503错误。
Server.js: Server.js:
var server_port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
server.listen(server_port, server_ip_address, function(){
console.log("Listening on " + server_ip_address + ",
server_port " +server_port);
});
package.json: 的package.json:
{
"scripts": {
"start": "supervisor server.js"
},
"main": "server.js"
}
I have gone through my logs and everything, and it says there is an issue at line 5 on server.js. 我已经浏览了我的日志和所有内容,并且它说服务器上的第5行存在问题。 How is that so? 怎么会这样? Am I going crazy, or am I missing something? 我疯了,还是我错过了什么? The NPM modules are cleared, and the application says it is fine. NPM模块已清除,应用程序说它没问题。
This is not a replica of another post, because I have done all of those. 这不是另一篇文章的翻版,因为我做了所有这些。
Server Log Trail Error: 服务器日志跟踪错误:
ReferenceError: server is not defined
at Object.<anonymous> (/var/lib/openshift/550764f6e0b8cd8a8a00007e/app- root/runtime/repo/server.js:4:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
DEBUG: Program node server.js exited with code 8
DEBUG: Starting child process with 'node server.js'
/var/lib/openshift/550764f6e0b8cd8a8a00007e/app- root/runtime/repo/server.js:4
server.listen(server_port, server_ip_address, function(){
^
I have no idea what is going on. 我不知道发生了什么事。 I keep getting a server is undefined issue, and everything is done correctly from what I can see. 我不断得到一个服务器是未定义的问题,从我能看到的一切都正确完成。
You have a string opened at the end of line 5 and you never close it. 你在第5行的末尾打开了一个字符串,你永远不会关闭它。 change it to 改为
var server_port = process.env.OPENSHIFT_NODEJS_PORT || 8080
var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1'
server.listen(server_port, server_ip_address, function(){
console.log("Listening on " + server_ip_address
+ ", server_port " + server_port);
});
and you should be good to go 你应该好好去
If that is what your file actually looks like, it looks like you are missing a chunk of code: 如果这就是你的文件实际上是什么样子,看起来你错过了一大堆代码:
var ipaddress = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
var http = require('http');
var server = http.createServer(function(request, response) {
console.log((new Date()) + ' Received request for ' + request.url);
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write("Welcome to Node.js on OpenShift!\n\n");
response.end("Thanks for visiting us! \n");
});
server.listen( port, ipaddress, function() {
console.log((new Date()) + ' Server is listening on port 8080');
});
That code is referenced from this quickstart: https://github.com/openshift-quickstart/openshift-nodejs-http-and-websocket-example/blob/master/server.js 该快速入门引用了该代码: https : //github.com/openshift-quickstart/openshift-nodejs-http-and-websocket-example/blob/master/server.js
The references server.js includes some websocket code also, but you can ignore that (unless you want to use it, that's fine too) 引用server.js也包含一些websocket代码,但你可以忽略它(除非你想使用它,那也没关系)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.