简体   繁体   中英

Deploying a repository on an OpenShift node.js server

I'm using the Wercker Continuous Integration & Delivery Platform to test and deploy a BitBucket repository on a node.js OpenShift server. Wercker loads in the BitBucket repository, builds it, tests it in the node.js environment, and passes it without any issue. It's also checking the code with jsHint, and returns without any errors.

Wercker also indicates that the deployment passes without errors, as does OpenShift. The problem is that when I check the application URL provided to me by OpenShift, it results with a server error:

503 Service Temporarily Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

In troubleshooting this, I restarted the server (I'm running the basic account, and I have that option) but that doesn't seem to resolve the issue. Neither Wercker or Openshift indicate that there is a problem, but for some reason, I'm simply unable to access that domain without error.

How can I fix this (with the most basic tier)?

This was the solution:

I installed the RHC client tools available on the OpenShift website, checked the application logs, and found that OpenShift was unable to find a server.js file in the root directory. So I renamed my app.js file to server.js, and in my package.json I changed the "start" value to server.js. Then I configured the code in server.js file to the OpenShift environment variables, and that did it!

The server.js now reads:

var http = require('http');
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+'/');

I'm now able to connect to the application URL and get the basic "Hello World" response.

(If at this point you're still unable to connect to your application, restart your server, and that should do the trick.)

I hope this helps someone else in the future.

Here's a helpful resource that I leaned on: https://gist.github.com/ryanj/5267357

Your app should be able to listen to the IP and port defined by Openshift's reverse proxy.

You need to change the port number and perhaps the IP in the server configuration.

Explained here: OpenShift node.js Error: listen EACCES

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