Skip to content

Instantly share code, notes, and snippets.

@Igloczek
Last active December 1, 2025 15:23
Show Gist options
  • Select an option

  • Save Igloczek/85ec5914dd56265554672b04dd2bc7ee to your computer and use it in GitHub Desktop.

Select an option

Save Igloczek/85ec5914dd56265554672b04dd2bc7ee to your computer and use it in GitHub Desktop.

Revisions

  1. Igloczek revised this gist Dec 1, 2025. 1 changed file with 9 additions and 5 deletions.
    14 changes: 9 additions & 5 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,11 @@ 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:

    ```bash
    # 1. Create the plist file

    # Create log directory first
    mkdir -p "$(brew --prefix)/var/log"

    # Generate plist with expanded paths
    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">
    @@ -55,17 +59,17 @@ cat <<EOF > ~/Library/LaunchAgents/com.caddy.local-proxy.plist
    <key>KeepAlive</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/usr/local/var/log/caddy.log</string>
    <string>$(brew --prefix)/var/log/caddy.log</string>
    <key>StandardOutPath</key>
    <string>/usr/local/var/log/caddy.log</string>
    <string>$(brew --prefix)/var/log/caddy.log</string>
    </dict>
    </plist>
    EOF

    # 2. Create the central config
    # Create the central config
    echo -e "{\n local_certs\n}\nimport ${HOME}/Sites/*/Caddyfile" > $(brew --prefix)/etc/Caddyfile

    # 3. Load the service
    # Load the service
    launchctl load ~/Library/LaunchAgents/com.caddy.local-proxy.plist
    ```

  2. Igloczek revised this gist Dec 1, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -47,7 +47,7 @@ cat <<EOF > ~/Library/LaunchAgents/com.caddy.local-proxy.plist
    <string>$(which caddy)</string>
    <string>run</string>
    <string>--config</string>
    <string>/usr/local/etc/Caddyfile</string>
    <string>$(brew --prefix)/etc/Caddyfile</string>
    <string>--watch</string>
    </array>
    <key>RunAtLoad</key>
  3. Igloczek revised this gist Dec 1, 2025. 1 changed file with 6 additions and 11 deletions.
    17 changes: 6 additions & 11 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -63,20 +63,20 @@ cat <<EOF > ~/Library/LaunchAgents/com.caddy.local-proxy.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
    echo -e "{\n local_certs\n}\nimport ${HOME}/Sites/*/Caddyfile" > $(brew --prefix)/etc/Caddyfile

    # 3. Load the service
    launchctl load ~/Library/LaunchAgents/com.caddy.local-proxy.plist
    ```

    ### 4. Trust the Root CA

    Caddy needs to be running first to generate the CA, then you trust it:

    ```bash
    caddy start --config $(brew --prefix)/etc/Caddyfile
    sudo caddy trust
    caddy stop
    ```

    _Note: If you see permission errors in logs, fix ownership of Caddy's data folder:_
    @@ -85,11 +85,6 @@ _Note: If you see permission errors in logs, fix ownership of Caddy's data folde
    sudo chown -R $(whoami) ~/Library/Application\ Support/Caddy
    ```

    ### 5. Start Caddy on boot
    ```bash
    brew services start caddy
    ```

    ## Adding a New Project

    1. Create `~/Sites/my-project/Caddyfile`:
    @@ -106,4 +101,4 @@ brew services start caddy
    ## Troubleshooting

    - **Check Logs:** `tail -f /usr/local/var/log/caddy.log`
    - **Restart Service:** `launchctl kickstart -k gui/$(id -u)/com.caddy.local-proxy`
    - **Restart Service:** `launchctl kickstart -k gui/$(id -u)/com.caddy.local-proxy`
  4. Igloczek revised this gist Dec 1, 2025. 1 changed file with 10 additions and 5 deletions.
    15 changes: 10 additions & 5 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -63,20 +63,20 @@ cat <<EOF > ~/Library/LaunchAgents/com.caddy.local-proxy.plist
    EOF

    # 2. Create the central config
    echo -e "{\n local_certs\n}\nimport ${HOME}/Sites/*/Caddyfile" > $(brew --prefix)/etc/Caddyfile
    # 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.plist
    ```

    ### 4. Trust the Root CA

    Caddy needs to be running first to generate the CA, then you trust it:

    ```bash
    caddy start --config $(brew --prefix)/etc/Caddyfile
    sudo caddy trust
    caddy stop
    ```

    _Note: If you see permission errors in logs, fix ownership of Caddy's data folder:_
    @@ -85,6 +85,11 @@ _Note: If you see permission errors in logs, fix ownership of Caddy's data folde
    sudo chown -R $(whoami) ~/Library/Application\ Support/Caddy
    ```

    ### 5. Start Caddy on boot
    ```bash
    brew services start caddy
    ```

    ## Adding a New Project

    1. Create `~/Sites/my-project/Caddyfile`:
  5. Igloczek revised this gist Dec 1, 2025. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -63,20 +63,20 @@ cat <<EOF > ~/Library/LaunchAgents/com.caddy.local-proxy.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
    echo -e "{\n local_certs\n}\nimport ${HOME}/Sites/*/Caddyfile" > $(brew --prefix)/etc/Caddyfile

    # 3. Load the service
    launchctl load ~/Library/LaunchAgents/com.caddy.local-proxy.plist
    ```

    ### 4. Trust the Root CA

    Caddy needs to be running first to generate the CA, then you trust it:

    ```bash
    caddy start --config $(brew --prefix)/etc/Caddyfile
    sudo caddy trust
    caddy stop
    ```

    _Note: If you see permission errors in logs, fix ownership of Caddy's data folder:_
  6. Igloczek revised this gist Dec 1, 2025. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -63,7 +63,11 @@ cat <<EOF > ~/Library/LaunchAgents/com.caddy.local-proxy.plist
    EOF

    # 2. Create the central config
    echo -e "{\n local_certs\n}\nimport ${HOME}/Sites/*/Caddyfile" > /usr/local/etc/Caddyfile
    # 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.plist
  7. Igloczek created this gist Nov 28, 2025.
    100 changes: 100 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,100 @@
    # Local Dev Proxy

    Automated local development proxy using Caddy. Handles HTTPS (`.test` domains) and HMR automatically.

    ## Setup (New Device)

    ### 1. Install Caddy

    ```bash
    brew install caddy
    ```

    ### 2. Install & Configure DNSmasq (Optional but Recommended)

    This enables wildcard DNS so all `.test` domains point to localhost automatically (no manual `/etc/hosts` editing).

    ```bash
    # 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'
    ```

    ### 3. Install the Caddy Service (Auto-Reloading)

    Run the following commands to set up the launchd agent that watches for config changes:

    ```bash
    # 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
    echo -e "{\n local_certs\n}\nimport ${HOME}/Sites/*/Caddyfile" > /usr/local/etc/Caddyfile

    # 3. Load the service
    launchctl load ~/Library/LaunchAgents/com.caddy.local-proxy.plist
    ```

    ### 4. Trust the Root CA

    ```bash
    sudo caddy trust
    ```

    _Note: If you see permission errors in logs, fix ownership of Caddy's data folder:_

    ```bash
    sudo chown -R $(whoami) ~/Library/Application\ Support/Caddy
    ```

    ## Adding a New Project

    1. Create `~/Sites/my-project/Caddyfile`:

    ```caddy
    my-project.test {
    reverse_proxy localhost:3000
    }
    ```

    2. **That's it.** Caddy automatically detects the new file, and DNSmasq routes the domain.
    (Visit `https://my-project.test`)

    ## Troubleshooting

    - **Check Logs:** `tail -f /usr/local/var/log/caddy.log`
    - **Restart Service:** `launchctl kickstart -k gui/$(id -u)/com.caddy.local-proxy`