Using Candy to Test and Develop with Local Custom Domains

Taron Foxworth
2 min readFeb 14, 2022

--

When developing locally, you may find yourself needing to test with an actual domain and not localhost.

Candy is a reverse proxy server written in Golang. It contains an HTTP, HTTPS, and DNS server 🚝. It’s simple and powerful.

Using candy we can start our local application on a port, and then run:

# addd candy configurationecho "8080" > ~/.candy/myapp # curl local domaincurl http://myapp.test

Now you can use myapp.test locally to access your application.

In this article, I’ll walk you through getting a simple environment spun up.

What is a reverse proxy server?

A reverse proxy server is a server that forwards requests from clients to other servers. This is often used to protect the privacy of clients by hiding the true identity of the server.

But, we can use that same feature locally to give you custom domains during development.

Getting started with Candy

For MacOS, you may run:

brew install owenthereal/candy/candy

See Installation Instructions for other operating systems.

Then, we need to run candy’s setup command:

sudo candy setup

Because you should always know what commands are doing to your machine, here is what it’s doing behind the scenes:

sudo mkdir -p /etc/resolver
cat<<EOF | sudo tee /etc/resolver/candy-test > /dev/null
domain test
nameserver 127.0.0.1
port 25353
search_order 1
timeout 5
EOF

Starting Candy

  1. Start candy:
brew services start candy

2. Start your local app.

3. Add port to candy as myapp:

echo "8080" > ~/.candy/myapp

4 . Restart candy:

brew services restart candy

5. Curl 😎:

curl http://myapp.test

For more configuration options, please see candy’s README.

Now you have a local domain to develop against.

☕ Enjoy!

Originally published at https://blog.taronfoxworth.com.

--

--

Taron Foxworth
Taron Foxworth

Written by Taron Foxworth

👋🏽 I’m Fox. I talk about computers, writing software, and making content. I’m CEO of Puzzle Labs.