Skip to content

Instantly share code, notes, and snippets.

@kenn
Created August 18, 2023 07:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenn/ac994506952618769b271591f0cb7e8a to your computer and use it in GitHub Desktop.
Save kenn/ac994506952618769b271591f0cb7e8a to your computer and use it in GitHub Desktop.
Keep separate cookies and passwords for multiple projects

Local Domains for Development

tl;dr

Install dnsmasq to make all .test domains point to localhost on your Mac.

Why and how to set up .test domain on your Mac

When we work on a local machine for development, we usually point to localhost:3000 in the browser. But using that domain for everything comes with some downsides when you work on multiple projects.

  • Cookies are shared between all projects
  • Saved passwords are shared between all projects

To solve those problems, it is recommended to assign an isolated domain for each project. (e.g. apple.test and orange.test)

There are reserved TLDs specifically designated for a testing use case, which will never be used in the real world. (RFC 2606)

  • .test
  • .example
  • .invalid
  • .localhost

And we choose .test here as it sounds the most appropriate for our use case, and is the shortest.

Here's how install and set up dnsmasq so that any domains and subdomains of .test will return 127.0.0.1.

brew install dnsmasq
mkdir -p $(brew --prefix)/etc/
echo 'address=/.test/127.0.0.1' > $(brew --prefix)/etc/dnsmasq.conf
sudo cp $(brew --prefix dnsmasq)/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
sudo mkdir /etc/resolver
sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/test'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment