简体   繁体   中英

NODE.JS - OpenShift 503 Service is Temporarily Unavilable: Server.js and Package.json files are fine

Project running on a Node.js Server:

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.

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:

 {
 "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. 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.

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. 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

The references server.js includes some websocket code also, but you can ignore that (unless you want to use it, that's fine too)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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