Pragmatism in the real world

Custom URLs for a Cloud Foundry application

Now that I have my application deployed to Cloud Foundry, I need it to work with my own domain, such as bookshelf.akrabat.com rather than slim-bookshelf.eu-gb.mybluemix.net. We can do this via the command line which is useful.

To do this we need to create a domain and then we can create a route.

Create a domain

To create a domain, we use the command cf create-domain {organisation name} {domain name}. For me, my organisation is “19FT”, so this is the command I use:

$ cf create-domain 19FT akrabat.com
Creating domain akrabat.com for org 19FT as rob@19ft.com...
OK

Now that we have a domain we can map a unique route to our application.

Mapping a route

Unsurprisingly, we use the map-route argument to create a route via the command line. This is needs to know which app we want to map to and then we can choose to add a sub domain (e.g. bookshelf.akrabat.com) and a path (e.g. akrabat.com/slimbookshelf). We can even combine the two for something like slim.akrabat.com/bookshelf if we wanted to.

The full command is cf map-route {app name} {domain name} --hostname {hostname} --path {path}, so for this example I use:

$ cf map-route slim-bookshelf akrabat.com --hostname bookshelf
Creating route bookshelf.akrabat.com for org 19FT / space demo as rob@19ft.com...
OK
Adding route bookshelf.akrabat.com to app slim-bookshelf in org 19FT / space demo as rob@19ft.com...
OK

We’re all done with the Cloud Foundry side. The last thing we need to do is set up a DNS record.

Set up DNS

To make everything work, create a CNAME DNS record from your route to the provider’s domain for your application (Bluemix in this case). Hence, I create this in my bind configuration:

bookshelf IN CNAME slim-bookshelf.eu-gb.mybluemix.net.

That’s it! Our own domain will now work with our shiny Cloud Foundry hosted application.