608.620.5104 | info@tenforward.consulting

Jellybean-surprise! (Or, how to change "localhost" to whatever you fancy)

Published March 16, 2016

I recently realized I could set localhost aliases that mapped the different roles of the software I'm building. For example, if an application has three user roles ("client", "coach", "admin"), I set up aliases for each that point to a logged-in user of that role. So when I visit client:3000 , I know that I'll be logged in as a client. When I visit admin:3000 , I know that I'll be logged in as an admin user, and so on. (Of course, there are also fun reasons to do this, as well, as we'll see below ☺️)

The following instructions are for Mac; find instructions for Windows here and instructions for Linux here.



 

1. Open your hosts file

Open your hosts file from terminal with whatever text editor you prefer: $ sudo subl /etc/hosts, $ sudo vim /etc/hosts, $ sudo nano /etc/hosts, you get the picture. You might be asked for your admin password.

Sample hosts file:


2. Add your new aliases

Copy the line that says 127.0.0.1 localhost and add a new line, but change localhost to whatever you want:

Save (after potentially entering your admin password again), and you're set! You can have multiple aliases direct to 127.0.0.1 - they don’t override each other.

Now, instead of seeing localhost:3000, you can be greeted with

and who doesn’t want that?

Author details

Hilary Stohs-Krause

Co-Owner and Senior Software Developer
@hilarysk