# Reverse proxy + LAN landing + automatic HTTPS (Let's Encrypt HTTP-01).
#
# Prerequisites:
#   1. cloudflare-ddns points A records at this host's public IPv4
#   2. Router port-forwards WAN :80 and :443 → this host
#   3. DNS-only (grey cloud) for names used here — orange-cloud breaks HTTP-01 to origin
#   4. Domain is devopshomelab.com (Cloudflare zone). If you meant .org, change all hostnames.
#
# Email for ACME registration (set in compose): CADDY_EMAIL

{
	email {$CADDY_EMAIL}
}

# --- HTTPS reverse proxies ---------------------------------------------------

forgejo.devopshomelab.com {
	encode gzip
	reverse_proxy forgejo:3000
}

jellyfin.devopshomelab.com {
	encode gzip
	reverse_proxy jellyfin:8096
}

# Info page only — RustDesk clients use TCP/UDP 21115–21119, not this site
rustdesk.devopshomelab.com {
	encode gzip
	header Content-Type "text/html; charset=utf-8"
	respond `<!DOCTYPE html><html><head><meta charset="utf-8"><title>RustDesk</title>
<style>body{font-family:system-ui;background:#0c0e12;color:#e8ecf4;max-width:40rem;margin:3rem auto;padding:0 1rem;line-height:1.5}
code{background:#1a1f2a;padding:.15rem .4rem;border-radius:4px;color:#6ea8fe}</style></head>
<body>
<h1>RustDesk server</h1>
<p><strong>ID / rendezvous server:</strong> <code>rustdesk.devopshomelab.com</code></p>
<p><strong>Relay server:</strong> <code>rustdesk.devopshomelab.com</code> (port <code>21117</code>)</p>
<p>In the RustDesk client: Network → ID server = hostname above. Paste the server public key from the host admin.</p>
<p>Open ports on the router/firewall: <code>21115–21119</code> TCP and <code>21116</code> UDP.</p>
</body></html>` 200
}

www.devopshomelab.com {
	redir https://devopshomelab.com{uri} permanent
}

devopshomelab.com {
	encode gzip
	root * /srv
	file_server
	try_files {path} /index.html
}

# --- HTTP :80 (ACME + LAN IP landing) ----------------------------------------

:80 {
	@lan {
		host 192.168.8.123 localhost 127.0.0.1
	}
	handle @lan {
		root * /srv
		encode gzip
		file_server
		try_files {path} /index.html
	}

	@acme_hosts {
		host devopshomelab.com www.devopshomelab.com forgejo.devopshomelab.com jellyfin.devopshomelab.com rustdesk.devopshomelab.com
	}
	handle @acme_hosts {
		redir https://{host}{uri} permanent
	}

	# Default: still serve the map (LAN hostname / other access)
	handle {
		root * /srv
		encode gzip
		file_server
		try_files {path} /index.html
	}
}
