-
Notifications
You must be signed in to change notification settings - Fork 18
Hosting boombot with a webpage on top
#Making use of node hosting to run a turntable bot
See original blog post here
Well my good friend over at Terrordactyl designs decided it was time to release a new version of his well known turntable.fm bot, Boombot. With his new version comes more modularity and control over scripting and admin access. If you want to know more about the original bot check it out on github here.
What I want to show you today, is how to get this bot to run on a provider like heroku or nodejitsu. If you've ever tried to push to there before you know that it fails, or might run for a little while then die. I'm not sure why it does, but it might have something to do with a keepalive or timeout on their servers. Update! It seems to work on heroku, provided you arbitrarily name your process (but we want to do something cooler with it.....)
I know this might seem like a waste of the hosting power but I liked it for my little dev sandbox. I also must assert that there are no warranties or guarantees that this will work for you and I'm not responsible for anything that could happen.
To start, I assume you've used and are comfortable with Git, Heroku, HTML/CSS, and Boombot, and possibly node (though most of it is already done for you). Once you have forked boombot from Terrordactyl designs go ahead and clone your repo locally. Open up your favorite text editor, Sublime text 2 and start a new file called webserver.js.
We're going to create a small web server that you will be able to build on later, but for now we'll make a blank site. The first thing we want to do in webserver.js is require http-server.
var HTTPServer = require('http-server').HTTPServer;
After we've required that we need to require our boomer (assuming you're using the newest version, 2.0.2 at the time of this writing).
var boomer = require ('./bin/boombot').bot;
Now that we have our requires we want to create the http-server. You'll notice the process.env.port line. This is important when hosting on heroku or jitsu. This will give you what ever arbitrary port number they assign you instead of tryin to run it on port 80 (which would fail...)
var httpServer = new HTTPServer({
root: './site/',
port: process.env.PORT || process.env.C9_PORT || 80
});
In my main folder I have a folder called site. This is where the site will go that we're putting on top of boombot. Create the folder now and put a blank or one line index.html in there for testing.
Back to the webserver.js file. Now that the http server is created lets start it and handle termination.
httpServer.start();
process.on('SIGINT', function() {
httpServer.log('http-server stopped.'.red);
return process.exit();
});
That should do it for the webserver.js.
In order to require boombot we have to export him somewhere along the lines. Open your bin/boombot file in Sublime text 2. At the very bottom we want to add our export
var bot = Boombot.loadBot(config);
var boombot = Boombot.run(bot, events, commands, config);
module.exports.bot = bot;
Add a procfile to your folder, and you're ready to test and deploy to Heroku! The procfile is simply "web: node webserver.js" if you don't know how to use them, check the heroku documentation.
Note: You may have to run sudo node webserver.js in order to test locally due to the default port being 80. You may also change that to any port you'd like to avoid having to sudo. I just like typing localhost and getting there. Stay tuned for the next installment where we'll set up our website to create something even cooler.