Deploying To Heroku

Once you've built your application, the next step could be making it available to the web. Today there are guite a few clound application platforms such as AWS, Microsoft Azure, Heroku, etc. that you can choose to deploy your application without having to build your own server. Below we'll take Heroku as an example and show you how to deploy coServ app to Heroku.

Note: To deploy to Heroku as suggested in this chapter, you'll need v0.10.3 or newer version of coServ.

Package Your App

coServ is designed not just to be a server for development purpose. It can also be used for production. In that case, running multiple websites on coServ would be the norm, so coServ reads configuration files to properly start up each website running on it. However, if you want to use a free dyno on Heroku to deploy your coServ app, this could be a problem. To deploy to Heroku, you'll have to package coServ as a single app rather than a platform. So the idea is to package your website like a node.js package and the rest would be a standard Heroku deploy procedure.

Assuming your website is code-named "onePage", the image below showing what the package would look like:

a coServ project

As you can see, it's very much a standard node package (or github reposiroty). The idea is to make your website a node package and make coServ the module your website depends on. In the above example, "onePage" is the directory of your website. "Procfile" will be read by Heroku to start up your app. "startWeb.js" is a simple program to create a coServ instance, initialize it and run it. Below is a sample:

var  serverConfig = {
        "apiEngine": {
            "host": "coimapi.net",
            "port": 80,
            "method": "POST",
            "version": "v2"
        },
        "server": {
            "wwwPath": __dirname,
            "port": process.env.PORT,
            "maxSockets": 200
        }
     },
     coServ = require('coserv');

coServ.init(serverConfig);
coServ.restart();

If you need an example, you can check the one page demo or install the demo directly from npm:

npm install cows-onepage

That demo is ready to be deployed to Heroku right out of the box.

Deploy to Heroku

Once you've packaged your website as suggested, the rest should be fairly easy. We'll not repeat the guides given by Heroku here. You can check Heroku git deployment guide for details.

results matching ""

    No results matching ""