Install dnsmasq
to make all .test
domains point to localhost
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'