How to server static assets on an Openshift NodeJS app How to server static assets on an Openshift NodeJS app nginx nginx

How to server static assets on an Openshift NodeJS app


This may suit your needs. Bare as it gets static server...

var finalhandler = require('finalhandler')var http = require('http')var serveStatic = require('serve-static')// Serve up public/ftp foldervar serve = serveStatic('public/', {'index': ['index.html']})// Create servervar server = http.createServer(function(req, res){    var done = finalhandler(req, res)    serve(req, res, done)})// Listenserver.listen(process.env.PORT || 3000);


It's been a while since the original question was posted, but maybe this will help other people facing the same issue. Have a look at this custom OpenShift cartridge here: https://github.com/gsterjov/openshift-nginx-cartridge

I haven't tested it personally, but I've built other custom cartridges and I know the OpenShift platform is quite flexible if you're proficient enough with the shell, so if the above cartridge doesn't suit your needs you can easily fork it and tweak it as you see fit.

Personally I'm almost always serving static assets from Node.js. The built-in static server in Express.js got so much better lately and there's also st if you need more control over caching / etags.

Also, I've recently came across this interesting CDN-like alternative to "classic" hosting for static assets: http://surge.sh. I can imagine it would be fairly trivial to implement a gulp/grunt scenario for publishing your static assets on surge on deployment...