node.jsherokugruntjs

How can I deploy a reveal.js app to heroku?


I am trying to deploy a reveal.js application to Heroku. Reveal.js runs on node via grunt connect command. The app also requires ruby for compiling assets on-the-fly. Locally, I can run the app by using grunt serve.

Initially, because of compass being a dependency of grunt watch, Heroku only detected the Gemfile and assumed I was running a ruby app. I used the nodejs custom buildpack to force Heroku to see it as a nodejs app.

Procfile contains

web: grunt serve

Log shows

 2013-06-17T13:51:56.187012+00:00 heroku[router]: at=error code=H14 desc="No web processes running"

heroku ps shows nothing either. I can run "heroku run grunt serve" successfully, and I have modified the default Gruntfile.js that comes with reveal to accept process.env i.e.

connect: {
  server: {
    options: {
      port: process.env.PORT || 8000,
      base: '.'
    } 
  }
}

As a last attempt, I tried using the Heroku-nodejs-grunt build pack (https://github.com/mbuchetics/heroku-buildpack-nodejs-grunt) which will run a grunt task on deploy to compile assets. Still no luck, heroku logs --tail still shows no process running. Exploring with heroku run reveals that grunt is available, and the grunt serve command successfully executes.

When starting to use the new grunt build pack I got an error with the above Gruntfile.js saying "process" is undefined. I switched the port to 0.

The port on which the webserver will respond. The task will fail if the specified port is already in use. You can use the special values 0 or '?' to use a system-assigned port.

Didn't work, tried "?", didn't work (still no web process and heroku restart doesn't do anything)

I can't figure out how to get Heroku to use grunt serve as my main web server process!


Solution

  • I was able to make it work using nodejs and expressJs.

    By following the heroku "getting started with nodejs", I was able to get a working webapp with expressjs and by declaring this in the web.js:

    var express = require("express");
    var app = express();
    app.use(express.logger());
    app.use("/", express.static(__dirname));
    
    var port = process.env.PORT || 5000;
    app.listen(port, function() {
      console.log("Listening on " + port);
    });
    

    With this you serve everything from / statically.

    You have the sources here: https://github.com/MichaelBitard/revealjs_heroku and a working example here: http://murmuring-cove-4212.herokuapp.com/