Skip to content

Instantly share code, notes, and snippets.

@kiliman
Last active October 8, 2025 01:36
Show Gist options
  • Save kiliman/38c2d279b60d2474e3c77a0f8e893291 to your computer and use it in GitHub Desktop.
Save kiliman/38c2d279b60d2474e3c77a0f8e893291 to your computer and use it in GitHub Desktop.
Use Caddy to debug production site
#!/bin/bash
set -e
SCRIPT_DIR=$(dirname "$(realpath "$0")")
sudo bash "$SCRIPT_DIR/update-hosts" add "$1" "127.0.0.1"
sudo bash "$SCRIPT_DIR/update-hosts" add "$1" "::1"

Debugging a production site locally

Add domain to hosts file (script runs sudo)

add-host your.domain.com

Use Caddy to act as SSL reverse proxy

One-time setup

brew install caddy

In one tab, start up Orchid using the production config (this sets API_BASE to production Swarm backend)

doppler run --project orchid --config prd -- pnpm --filter orchid dev

In a second tab, start up Caddy. This will create a reverse proxy to orchid (port 3004). It will automatically create certificates for the specified domain.

caddy reverse-proxy --to ":3004" --internal-certs --from "your.domain.com"

Clear Chrome host cache

Open Chrome to chrome://net-internals/#dns and click Clear host cache. This will ensure that Chrome picks up the host names you added to /etc/hosts

You can now open your browser to https://your.domain.com and you'll see that your local Orchid app is serving the domain. Since you've updated the Doppler config, it is hitting the production Swarm.

NOTE: If the browser complains about the certificate, just proceed anyway.

Cleanup

When you're done with your debugging session, be sure to undo the steps you performed above:

  1. Stop the caddy process (Ctrl-C or close the terminal)

  2. Remove the domain from the hosts file

rm-host your.domain.com
#!/bin/bash
set -e
SCRIPT_DIR=$(dirname "$(realpath "$0")")
sudo bash "$SCRIPT_DIR/update-hosts" remove "$1"
#!/bin/bash
# Function to display usage
usage() {
echo "Usage: $0 {add|remove} hostname [ip_address]"
exit 1
}
`
# Check if the user provided enough arguments
if [ "$#" -lt 2 ]; then
usage
fi
# Assign arguments to variables
ACTION=$1
HOSTNAME=$2
IP=${3:-127.0.0.1} # Default IP address is 127.0.0.1
# Function to add a host
add_host() {
if grep -q "$IP $HOSTNAME" /etc/hosts; then
echo "$HOSTNAME already exists in /etc/hosts with IP $IP"
else
echo "$IP $HOSTNAME" >> /etc/hosts
echo "$HOSTNAME added to /etc/hosts with IP $IP"
fi
}
# Function to remove a host
remove_host() {
if grep -q "$HOSTNAME" /etc/hosts; then
sed -i.bak "/$HOSTNAME/d" /etc/hosts
echo "$HOSTNAME removed from /etc/hosts"
else
echo "$HOSTNAME not found in /etc/hosts"
fi
}
# Perform the action
case $ACTION in
add)
add_host
;;
remove)
remove_host
;;
*)
usage
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment