# Caddy config.
#
# - gendsgn.ru — main production site, auto-TLS via Let's Encrypt.
# - www.gendsgn.ru — 301 redirect to apex (canonical URL).
# - :80 — fallback for raw IP access. Will be removed once everyone uses the domain.
#
# `handle /api/*` (NOT `handle_path`) — we keep the /api prefix because
# the FastAPI router is mounted at /api/v1/*.

gendsgn.ru {
    encode zstd gzip

    handle /api/* {
        reverse_proxy backend:8000
    }

    handle /health {
        reverse_proxy backend:8000
    }

    handle {
        reverse_proxy frontend:3000
    }
}

www.gendsgn.ru {
    redir https://gendsgn.ru{uri} permanent
}

# Plain HTTP by IP — kept for ssh-tunnel / debugging.
# Caddy issues no TLS here (no hostname).
:80 {
    encode zstd gzip

    handle /api/* {
        reverse_proxy backend:8000
    }

    handle /health {
        reverse_proxy backend:8000
    }

    handle {
        reverse_proxy frontend:3000
    }
}
