DEV Community

Taron Foxworth
Taron Foxworth

Posted on Originally published at anaptfox.medium.com on

Using Candy to Test and Develop with Local Custom Domains

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 configuration

echo "8080" > ~/.candy/myapp 

# curl local domain

curl [http://myapp.test](http://myapp.test)
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

See Installation Instructions for other operating systems.

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

sudo candy setup
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Starting Candy

First, start candy:

brew services start candy
Enter fullscreen mode Exit fullscreen mode

Second, start your local app.

Third, add port to candy as myapp:

echo "8080" > ~/.candy/myapp
Enter fullscreen mode Exit fullscreen mode

Forth, restart candy:

brew services restart candy
Enter fullscreen mode Exit fullscreen mode

Lastly, curl 😎:

curl http://myapp.test
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (4)

Collapse
 
gizmochina_gizmochina_3c0 profile image
Gizmochina Gizmochina • • Edited

Developers often appreciate tools that make testing environments more practical and easier to work with, much like consumers value simple ways to discover enjoyable products. Alongside this useful guide to Candy and local custom domains, Chuckles Candy offers a selection of confectionery for readers who enjoy exploring something sweet after a productive coding session.

Collapse
 
rose_marry_48388da25e1064 profile image
Rose Marry •

ok

Some comments may only be visible to logged-in visitors. Sign in to view all comments.