Basic Deployment

Introduction

This article is based upon this guide and the following method is only applicable to deployment on Heroku.

Video Guide

Prerequisites

First you will need to create a Heroku account and a MongoDB Atlas account. For better security it is advised that you install OpenSSL on your local machine. This can be done through the command line on UNIX (Mac OS X, Linux) based systems. The easiest way to do so on windows would be to install the 'Git for Windows' package or on Windows 10, utilising the Bash for Windows 10 shell.

Signup for Heroku

Signup for MongoDB Atlas

Git For Windows (OpenSSL)

OpenSSL for Mac OS X

OpenSSL for Ubuntu Linux

Setting up your database

We will be hosting the data from our survey on a seperate remote host. This can be done either through MongoDB Atlas or mLab.

Mongo Atlas

First, go to MongoDB Atlas and sign up for a free account. MongoDB Atlas is a Database as a Service provider that provides encrypted remote mongoDB instances, which we will use to store the survey recipient data, with free and paid tiers of service. MongoDB Atlas clusters make use of the General Purpose SSD (gp2) EBS volumes, with AES-256 encryption.. All communication to and from the server is also encrypted from MOTM attacks through the use of TLS/SSL socket security.

Next, select your server provider. It is recommended that you select the free AWS service tier (M0) with 512MB of storage. (This is in fact approximately enough for at least ~250,000 survey responses and thus should be sufficient even for live deployment.)

Now, after your cluster has finished initialising, go to the Security > MongoDB Users Tab and add a new user.

Enter a username (such as admin) and a password. This will be used by the application itself in a driver to access your database. Ensure that Read and Write access is checked. Please remember and copy down this password and save it for later, as you will need this information later.

Now go to the Security > IP Whitelist tab, and add a new IP Address.

You will want to repeat this process twice, as you will need to allow access firstly from your own IP address, as well as any IP address (for now). This is because the free version of the Heroku application uses a dynamic IP address which changes from time to time, whilst paid tiers of Heroku allow for a fixed static IP, which we can later add to the whitelist (whilst removing the 0.0.0.0/10 entry) for better security later on.

At this point, if you wish to connect to a desktop client for viewing your remote database data directly (not through the QMd application, you may install MongoDB Compass and follow the MongoDB Compass Install guide.

Now navigate to the Clusters > Overview page and click connect.

Select the option to "Connect Your Application"

We will now need to generate the string for our application's mongoDB driver.

Copy this string to your clipboard, or on a notepad document for later. We will need this when we finally initialise our heroku application.

Generating Secure Elements

As we have a login gate, in addition to providing both a user/password pair that is valid to allow for administrator access to our application, as well as generate 2048 bit RSA-256 keys for the purposes of encryption and authentication of admin logins.

To generate the RSA keys, the easiest method would be to use an online RSA key generator such as JSEncrypt.

However, for better security, it is advisable to generate the RSA keys on your local machine using OpenSSL. Once installed, open a command line window and run the following code

openssl genrsa -out private.key openssl rsa -in private.key -pubout > public.key

In the root folder of your terminal window, two new files will be generated corresponding to the private and public keys. You may open these files with notepad and save them for later.

Initialising Heroku

Now that our database has been fully setup, including a compass client for monitoring and viewing raw database data, we can now create a heroku application with a link to the mongoDB database.

First, click this button.

This will automatically handle the deployment of the application for you, no hands on required! Note that this means you will have no control over the basic settings and file configuration, so for a more advanced setup, use the advanced setup guide.

Next, enter the driver link you copied earlier and put it in the text field provided below.

You also need to provide a username and password (to log into the administrator interface) and to provide the RSA public and private keys you generated earlier.

Click deploy app, wait for the application to deploy and then open the URL in your browser. It may take some time to load as the server has to "wake up" first (free Heroku apps go to sleep after 30 minutes).

Custom Domain Names

https://devcenter.heroku.com/articles/custom-domains

By default, a Heroku app is available at its Heroku domain, which has the form [name of app].herokuapp.com. For example, an app named serene-example-4269 is hosted at serene-example-4269.herokuapp.com.

To make your app available at a non-Heroku domain (for example, www.yourcustomdomain.com), you add a custom domain to it.

You can add custom domains to any Heroku app for free (however the domain name itself will have to be paid for). For security purposes, you must verify your Heroku account to add domains to apps.

Heroku does not provide a domain registration service (for registering a custom domain name) or a DNS provider service (for hosting the DNS servers that point your custom domain name to your app).

Exporting Raw JSON data from Database

Last updated