OUTDATED

If you need to host a jive sdk service (jivesoftware/jive-sdk · GitHub) somewhere on the Internets, Heroku (https://www.heroku.com) is a pretty good choice, along with Nodejitsu. For the purposes of this blogpost, I'll be talking about Heroku.

 

I'm assuming that you've already:

 

  1. Generated a jive-sdk service
  2. Signed up for Heroku
  3. Uploaded your service to Heroku

 

After having done the above, you'll need to add mongodb to your app:

 

heroku addons:add mongolab

 

MongoDB is required on Heroku, because Heroku uses a virtual file system that makes it impossible to use the sdk's default filesystem persistence. Setting up mongoDB persistence for your service is pretty easy.

 

Your package.json should have this dependency:

"jive-persistence-mongo" : "*"

And your jiveclientconfiguration.json should have this:

"persistence" : "jive-persistence-mongo"

Finally, the app.js generated by the SDK won't play nicely with Heroku's requirement that it controls the HTTP port and mongoDB URL. You can get around this by using the following app.js:

 

var express = require('express'),
    http = require('http'),
    jive = require('jive-sdk');
var app = express();

var failServer = function(reason) {
    console.log('FATAL -', reason );
    process.exit(-1);
};

var startServer = function () {
    if ( !jive.service.role || jive.service.role.isHttp() ) {
        var server = http.createServer(app).listen( app.get('port') || process.env.PORT, function () {
            console.log("Express server listening on port " + server.address().port);
        });
    }
};

jive.util.fsreadJson('jiveclientconfiguration.json').then( function(options) {
    options['port'] = process.env.PORT || options['port'];
    options['databaseUrl'] = process.env.MONGOLAB_URI || process.env.MONGOHQ_URL || options['databaseUrl'];
    jive.service.init(app, options)
        .then( function() { return jive.service.autowire() } )
        .then( function() { return jive.service.start() } ).then( startServer, failServer );
});

 

What this is doing is reading in your jiveclientconfiguration.json file and then overriding the port and databaseUrl parameters from environment process variables set by Heroku. This app.js should work running locally, or in Heroku!