custom local domain aliases for local dev servers
Localias is a tool for developers to securely manage local aliases for development servers.
Use Localias to redirect https://server.test → http://localhost:3000 in your browser and on your command line.
/etc/hosts as you add and remove aliases, so that they
work with all of your tools.caddy so it's fast and secure by default..local domains over mDNS, so you can visit your development
servers from your phone or any other device connected to the same network.# install it
brew install peterldowns/tap/localias# run it
go run github.com/peterldowns/localias/cmd/localias@latest --help
# install it
go install github.com/peterldowns/localias/cmd/localias@latest# run it
nix run github:peterldowns/localias -- --help
# install it
nix profile install --refresh github:peterldowns/localiasVisit the latest Github release and pick the appropriate binary. Or, click one of the shortcuts here:
Localias has two parts:
The configuration file is where Localias keeps track of your aliases, and to which local ports they should be pointing. The proxy server then runs and actually proxies requests based on the configuration.
Every time you run localias, it looks for a config file in the following places, using the first one that it finds:
--configfile <path>, it will attempt to use <path>LOCALIAS_CONFIGFILE=<path>, it will attempt to use <path>.localias.yaml, it will use $pwd/.localias.yaml.localias.yaml at the root of the repository, use $repo_root/.localias.yaml$XDG_CONFIG_HOME/localias.yaml, creating it if necessary.~/Library/Application\ Support/localias.yaml~/.config/localias.yamlThis means that your whole dev team can share the same aliases by adding .localias.yaml to the root of your git repository.
To show the configuration file currently in use, you can run
# Print the path to the current configuration file
localias debug config
# Print the contents of the current configuration file
localias debug config --printThe following commands all interact directly with the configuration file:
# add or edit an alias
localias set <alias> <port>
# clear all aliases
localias clear
# list all aliases
localias list
# remove an alias
localias remove <alias>
# import all the aliases from another config file
localias import path/to/another/config/localias.yamlThe configuration file is just a YAML map of <alias>: <port>! For example, this is a valid configuration file:
bareTLD: 9003 # serves over https and http
implicitly_secure.test: 9002 # serves over https and http
https://explicit_secure.test: 9000 # serves over https and http
http://explicit_insecure.test: 9001 # serves over http onlyWhen you execute localias run or localias start to run the proxy server, Localias performs the following operations:
/etc/hosts file to make sure that every alias is presentsudo privileges.Localias requires elevated privileges to perform these actions as part of running the proxy server:
/etc/hostsWhen you run Localias, each time it needs to do these things, it will open a subshell using sudo to perform these actions, and this will prompt you for your password. Localias does not read or interact with your password.
Localias is entirely local and performs no telemetry.
After installing localias, you will need to configure some aliases. For this quickstart example, we'll assume that you're running a local http frontend devserver on http://localhost:3000, and that you'd like to be able to access it at https://frontend.test in your browser and via tools like curl.
First, create the alias:
$ localias set frontend.test 3000
[added] frontend.test -> 3000You can check to see that it was added correctly:
$ localias list
frontend.test -> 3000That's it in terms of configuration!
Now, start the proxy server. You can do this in the foreground with localias run (and stop it with ctrl-c) or you can start the server in the background with localias start. For the purposes of this quickstart, we'll do it in the foreground.
…This will prompt you to authenticate at least once. Each time Localias runs, it will
/etc/hosts file and add entries for each of your aliases.Each of these steps requires sudo access. But starting/stopping Localias will only prompt for sudo when it needs to, so if you hit control-C and restart the process you won't get prompted again:
^C
$ localias run
# ... lots of server logs
# ... but no sudo prompts!Congratulations, you're done! Start your development servers (or just one of them) in another console. You should be able to visit https://frontend.test in your browser, or make a request with curl, and see everything work perfectly*.
* are you using Firefox, or are you on WSL? See the notes below for how to do the one-time install of the localias root certificate
Instead of explicitly running the proxy server as a foreground process with localias run, you can also run Localias in the background with localias start. You can interact with this daemon with the following commands:
# Start the proxy server as a daemon process
localias start
# Show the status of the daemon process
localias status
# Apply the latest configuration to the proxy server in the daemon process
localias reload
# Stop the daemon process
localias stopWhen running as a daemon process, if you make any changes to your configuration you will need to explicitly reload the daemon:
# Start with frontend.test -> 3000
localias set frontend.test 3000
localias start
# Update frontend.test -> 4004.
localias set frontend.test 4004
# The daemon will still be running with frontend.test -> 3000, so
# to apply the new changes you'll need to reload it
localias reloadlocalias has many different subcommands, each of which is documented
(including usage examples). To see the available subcommands, run localias. To
see help on any command, you can run localias help $command or
localias $command --help.
…Localias is the tool I've always wanted to use for local web development. After years of just visiting localhost:8080, I finally got around to looking for a solution, and came across hotel (unmaintained) and its fork chalet (maintained). These are wonderful projects that served as inspiration for Localias, but I think Localias is implemented in a better and more useful way.
Finally, my friend Justin wanted this to exist, too:
I swear there's a tool that lets me do:
localhost:8000 → application.local
localhost:3000 → marketing.local
localhost:3002 → docs.localBut I can't for the life of me remember the name of it. Does anyone know what I'm talking about?
Localias is designed to replace alternative tools like hotel/chalet. Hotel is no longer maintained, and Chalet is a fork of Hotel with basically the same features. I think Localias compares favorably:
/etc/hosts (and the windows equivalent), which makes it easy to observe and debug. Hotel requires you to configure itself as a proxy in your browser or in your operating system.curl. Hotel aliases only work in your browser.When using Localias, you should not create aliases with the same name as existing websites. For instance, if you're working on a website hosted in production at https://example.com, you really do not want to create a local alias for example.com to point to your development server. If you do,
your browser may do things you don't expect:
No open issues yet, or sync has not completed.