Site hosting on Assembla.com

Rdbhost makes relational databases available to JavaScript apps in the browser. You do have to host the static app pages somewhere, and while you can store static pages (and other files) on Rdbhost, other options can be attractive. Assembla will host pages, under your domain name even, with subversion as the deployment mechanism, and can be used to host the static part of your database-backed JavaScript application.

Here is an overview of how to setup a site on assembla.com, with Rdbhost database hosting.

Create an Assembla Account:

This is very straightforward, following the prompts at assembla. You can create subversion and git accounts. Here we describe the subversion way.

Create a Directory in the Repository

Create a new directory in your repository for storing public files. You can name this directory as you like; this example uses a domain style name 'rdbhost.assembla.com'. Navigate to the new directory using the on-site repository browser.

assembla screenshot

Click the publish button and enter the chosen domain name, including subdomain as applicable.

assembla screenshot

We will assume sufficient familiarity with subversion to checkout the repository create the display directory, add new html content and commit all.

Setup Domains

To use the recommended JavaScript library for Rdbhost, you need a site domain that you own, and can setup subdomains on. In your domain registrar's domain manager, create a principle domain (with or without subdomain) that points at assembla.com, and another subdomain that points at www.assembla.me. For example, your assembla pages could be www.example.com, and the database subdomain would be rdbhost.example.com. This is the same general subdomain configuration used for a JavaScript app hosted anywhere. The domain/subdomain you point at assembla.com should be the one you entered in the publish page above.

The alternate JavaScript library relies on CORS (Cross Origin Resource Sharing) compliance by the user's browser, and only relatively modern browsers comply.

We have a tutorial on setting up domain pointers at GoDaddy, and the following is a screenshot of how one registrar handles zone editing, and Rdbhost's domain configuration.

dns screenshot

After you publish the subversion directory and update your dns, you should be able to access your static index.html at that domain. I read that several hours may be required to propogate dns records, but have personally observed propogation times of approx 5 minutes.

Develop Your App

Develop your app in your 'example.assembla.com' folder, and periodically commit it to the assembla.com repository. You will be able to test it at the internet domain as well as on localhost.

We have a demonstration app, on a.rdbhost.com, called 'Three Faves'. This is the simplest database example app I could think of that might be fun. You enter 3 favorite things, and it looks for other people in the database that also entered any of those things, and shows you what else they entered. It is completely anonymous, and has a crowd-sourced bad-words filter.

three faves screenshot

The source for this app is in the rdbhost.github.com public github repository. It is one-file resource, with css and javascript all rolled in there, except for the rdbhost.jquery.js database library.

Prior to writing and testing the application, put the Rdbhost server into training mode, where it accepts and white-lists any queries received from the training client machines. When the app is debugged, you can clear the white-list (also called the lookup.preauth_queries table) to remove cruft, and repopulate it by rerunning the application, and then turn training off. Training mode is enabled and disabled from the training page, linked from the account profile.

training screenshot

You also need to create the database roles that will query the database. Generally, for a JavaScript application, you would use the preauth or the auth role, perhaps in combination with the reader role. The roles are created from the role manager page. Privileges to the various tables and resources must be granted to the chosen roles, using SQL GRANT statements.

The 'Three Faves' app uses the preauth role, which is only permitted to run white-listed queries, so the database is protected from somebody trying to run arbitrary destructive queries as that role.

The creation of tables, views, indexes, etc, can be incorporated into your app, but the Rdbadmin utility is useful for creating initial tables and such. Use SQL GRANT to grant necessary privileges to the chosen roles.

role mgr screenshot

To summarize the main points:

  1. You can host static pages on www.assembla.com, under your own domain, and use Rdbhost hosted databases from those static pages.
  2. You need to point your own domain to your assembla page, and also point a subdomain at the Rdbhost server, in order for the JavaScript library to manage the cross-domain data transfer.
  3. Setup roles on Rdbhost, and grant appropriate privileges to tables and other resources..
  4. Create tables and indexes using the Rdbadmin utility.
  5. Put account in training mode, develop your application, clear the whitelist, repopulate with valid queries, and then disable training mode.