Skip to main content
Ben Nadel at cf.Objective() 2010 (Minneapolis, MN) with: Shannon Hicks
Ben Nadel at cf.Objective() 2010 (Minneapolis, MN) with: Shannon Hicks

Using A "dev.{base}.test" URL Pattern For Local Development

By
Published in

In my recent post on updating my Content Security Policy (CSP), Adam commented that my site doesn't have the Strict-Transport-Security (HSTS) HTTP response header. I used to have this security header enabled; but I removed it recently when I was trying to decouple my ColdFusion logic from the need to serve content over https://. After I removed it, I wasn't convinced that I needed to add it back; but after refreshing my understanding of what the HSTS header does, I've decided to add it back (via Cloudflare's edge certificate settings). But, before I do that, I wanted to move to a more strategic local development URL pattern for my ColdFusion applications.

Haphazard URLs of the Past

Historically, I've used one of three URL patterns in local development. Either a generic LocalHost URL:

Example: https://localhost

Or, a .local. subdomain:

Example: https://www.local.bennadel.com

Or, a .local top-level domain (TLD):

Example: https://www.bennadel.local

Each of these URL patterns is problematic in different ways.

The localhost domain is problematic because it groups all of my development efforts into a single web bucket. Which means that if I spin up localhost for Big Sexy Poems (BSP), the BSP application gets access to all of the same cookies, LocalStorage, etc that were created by the localhost for this blog. And vice-versa.

The .local. subdomain is problematic because it shares the same apex domain as my production site. Which means that if I ever need to enable a feature like HSTS — which can be applied to all subdomains — I'll end up applying it to both production and development environments simultaneously, which may not be what I want.

The .local TLD is problematic from a DX (developer experience) standpoint because my browser's universal bar is forever trying to auto-complete the URLs that I type. And when a TLD is the only part of the URL that differentiates production from development, it means that I have to manually manipulate the location bar more often. Which is just an ongoing point of friction!

New Double-Sided URLs

To address each of the aforementioned problems, I'm moving to a development URL pattern that includes both a prefix and a suffix:

dev.{base}.test

For example:

  • dev.www.bennadel.test
  • dev.www.bigsexypoems.test
  • dev.app.bigsexypoems.test
  • dev.app.digdeepfitness.test

The dev. prefix immediately differentiates the URLs in my browser's history, which makes the location autocomplete much more helpful. And the .test TLD gives my development site and my production site two separate apex domains so that they never share any web settings or storage data.

Aside: the .test TLD is a reserved value specified in RFC 2606. Its intention is to be used for testing when you want a TLD that's guaranteed to never conflict with a real TLD, both current and future.

To help enforce this in my local development environment, I've added a redirect rule to the rules section of my CommandBox server.json file. The rewrite rule checks the incoming host against the vanity host (and 127.0.0.1:8080) and redirects if neither match:

{
	"...": "... truncated file ...",
	"web": {
		"host": "127.0.0.1",
		"bindings": {
			"HTTP": {
				"enable": true,
				"listen": 8080
			},
			"SSL": {
				"enable": true,
				"listen": 8443
			}
		},
		"rules": [
			"not equals(%{i,Host}, 'dev.www.bennadel.test') and not equals(%{i,Host}, '127.0.0.1:8080') -> redirect('https://dev.www.bennadel.test%U%q')",
			"not is-file and not is-directory -> rewrite('/index.cfm%U')"
		]
	}
}

I'm allowing the 127.0.0.1:8080 host as this is what my scheduled task runner uses internally within the Docker container.

And, of course, I have to setup an entry in the /etc/hosts file on my Mac in order to get dev.www.bennadel.test — and every other local development URL — to resolve as 127.0.0.1. At first, I was going to try using the .localhost TLD since I just learned that Chrome and Firefox both auto-resolve said TLD to 127.0.0.1. But, my version of Safari doesn't yet do this. And so, if I need the /etc/hosts entry anyway, I might as well choose a slightly shorter TLD.

I feel good about this URL scheme because it's explicit; but it's not a hill I need to die on. If anyone has a different approach that they enjoy using, I'm open to any suggestions.

Want to use code from this post? Check out the license.

Reader Comments

Post A Comment — I'd Love To Hear From You!

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
— Ben Nadel
Managed ColdFusion hosting services provided by:
xByte Cloud Logo