0

I've done some updates to my node app, deployed to OpenShift and now it wont send the index.html file when live. I updated Express too and fixed all the errors from there...

My Directory structure is as follows:

/Site/
....server.js
....app/
........index.html/

My server looks like this:

var express = require('express');
var app = express();
var path = require('path');

app.use(express.static('app'));

require('./server-stripe.js')(app);

app.get('*', function(req, res) {
    res.sendFile(path.resolve(__dirname + 'app/index.html'));
});

var server_port = process.env.OPENSHIFT_NODEJS_PORT || 8080
var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || process.env.OPENSHIFT_INTERNAL_IP ||'127.0.0.1'

app.listen(server_port, server_ip_address, function () {
  console.log( "Listening on " + server_ip_address + ", server_port " + server_port )
});

It works fine on my local environment but in Production I get a 503 Service Unavailable.

Any advice would be greatly appreciated! Whits end and all that ;)

Thanks, Matt

Edit This is the log:

==> app-root/logs/haproxy.log <==
[WARNING] 009/181452 (443835) : Server express/local-gear is UP (leaving maintenance).
[WARNING] 009/181453 (443835) : Server express/local-gear is DOWN, reason: Layer7 wrong status, code: 404, info: "Not Found", check duration: 36ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[ALERT] 009/181453 (443835) : proxy 'express' has no server available!

==> app-root/logs/nodejs.log <==
Error: ENOENT, stat '/var/lib/openshift/539976e05004467473000668/app-root/runtime/repo/app/index.html'

I'm reading around the hapoxy stuff though I'm not too clued into it?

1 Answers1

0

Haproxy needs your app to serve something with http 200 OK response code, from root path (http://domain.name). Otherwise it will report your gear is DOWN. You may try checking the app with curl from the app's own gear, see the deployment log for IP and port.

To serve the static files from a selected folder (here "/app") without worrying about type recognition, you can use:

app.use(express.static(__dirname + '/app'));

If the native mime types are not enough, you can extend them:

express.mime.type['ogv'] = 'video/ogg';

Otherwise, see Basic static file server in NodeJS for a 'manual' implementation of static file server.

see: http://expressjs.com/api.html

Community
  • 1
  • 1
ptrk
  • 1,800
  • 1
  • 15
  • 24
  • Can I handle that in the node server? If I move my index.html into the root directory it serves the file, but none of the css/js has the correct mime types when it calls that.. – user2740151 Jan 11 '15 at 01:02