January 30, 2017 | Written by: Henrik Loeser
Categorized: Compute Services | How-tos
Share this post:
Recently, I have experimented with combining several runtimes and apps. You can read about my experiences in the blog “Manifest files: Understand Domain and Host Property for Your Bluemix Cloud Foundry Apps“. The reason behind my experiments were to put together a sample for Context Path Routing for use with IBM Bluemix Cloud Foundry apps. But what are context path routes and what does the sample do? Here are the details.
Cloud Foundry introduced Context Path Routing last year. Until then, there was the requirement that each app (or service) was served from its own hostname. Now, apps can share a host with each app being served from a specific path on that host. Here are three examples:
One Domain, Two Apps, Three Routes – Sample App using Context Path Routes
- When building a larger website, there could be several so-called microsites embedded. With Context Path Routing it is possible to serve, e.g., example.com from one web app and example.com/user-management or example.com/news from other apps. All these apps could be written in different programming languages such as Node.js, Python, Java and others.
- For a more complex microservice-based app, following the principles of the Twelve Factor App, there could be several (backing) services involved. The app and each would require their own hostname. With Context Path Routing the app could use app.mybluemix.net and services could be served from app.mybluemix.net/service1, app.mybluemix.net/service2, etc.
- It is possible to encrypt custom domains on Bluemix with the “Let’s Encrypt” Certificate Authority and related tools. It is based on the same principles as example one. Read here about how to use Context Path Routes and “Let’s Encrypt” to secure your custom domain.
Getting Started with Context Path Routes
So how could you use the new routing feature? There are several Cloud Foundry CLI commands related to routing. They allow to specify an additional path for application routes. Manifest files also have optional route properties that could be set. To get started, take a look at my Context Path Routing sample on GitHub for details. It has two small apps written in Python and Node.js that share a host using specific paths. The apps can be deployed with a single command and allow to experiment with context paths. The “What this samples does” section gives you some ideas.