Automated local development proxy using Caddy. Handles HTTPS (.test domains) and HMR automatically.
brew install caddyThis enables wildcard DNS so all .test domains point to localhost automatically (no manual /etc/hosts editing).
# Install DNSmasq
brew install dnsmasq
# Configure it to route .test to 127.0.0.1
echo 'address=/.test/127.0.0.1' > $(brew --prefix)/etc/dnsmasq.conf
# Start the service
sudo brew services start dnsmasq
# Register the resolver with macOS
sudo mkdir -p /etc/resolver
sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/test'Run the following commands to set up the launchd agent that watches for config changes:
# 1. Create the plist file
cat <<EOF > ~/Library/LaunchAgents/com.caddy.local-proxy.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.caddy.local-proxy</string>
<key>ProgramArguments</key>
<array>
<string>$(which caddy)</string>
<string>run</string>
<string>--config</string>
<string>/usr/local/etc/Caddyfile</string>
<string>--watch</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/caddy.log</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/caddy.log</string>
</dict>
</plist>
EOF
# 2. Create the central config
# Intel based Macs
echo -e "{\n local_certs\n}\nimport ${HOME}/Sites/*/Caddyfile" > /usr/local/etc/Caddyfile
# Apple Silicon based Macs
echo -e "{\n local_certs\n}\nimport ${HOME}/Sites/*/Caddyfile" > /opt/homebrew/etc/Caddyfile
# 3. Load the service
launchctl load ~/Library/LaunchAgents/com.caddy.local-proxy.plistsudo caddy trustNote: If you see permission errors in logs, fix ownership of Caddy's data folder:
sudo chown -R $(whoami) ~/Library/Application\ Support/Caddybrew services start caddy-
Create
~/Sites/my-project/Caddyfile:my-project.test { reverse_proxy localhost:3000 }
-
That's it. Caddy automatically detects the new file, and DNSmasq routes the domain. (Visit
https://my-project.test)
- Check Logs:
tail -f /usr/local/var/log/caddy.log - Restart Service:
launchctl kickstart -k gui/$(id -u)/com.caddy.local-proxy