# /etc/caddy/Caddyfile
# caddy add-package github.com/caddy-dns/cloudflare
# rm -f /opt/homebrew/etc/Caddyfile && ln -s /private/etc/caddy/Caddyfile /opt/homebrew/etc/Caddyfile && ls -la /opt/homebrew/etc/Caddyfile
(capacic) {
	encode zstd gzip
	request_body {
		max_size 500MB
	}
	root * /etc/caddy/html
	file_server {
		# If we visit /404.html directly we receive a 404 response, and not a 200.
		hide 404.html
		browse
		precompressed zstd gzip br
	}
	handle_errors {
		# https://caddyserver.com/docs/v2-upgrade#errors
		@404 {
			expression {http.error.status_code} == 404
		}
		rewrite @404 /404.html
		file_server
	}
	handle /api/send {
		reverse_proxy localhost:5959
	}
	handle /nc/api/send {
		reverse_proxy localhost:5959
	}
	handle /rest/nc/* {
		reverse_proxy localhost:5959
	}
	handle /rest/nw/* {
		reverse_proxy localhost:5959
	}
	handle /rest/ma/* {
		reverse_proxy localhost:5955
	}
	handle /nc/* {
		try_files {path} {path}/ {path}/index.html /nc/
	}
	handle /nw/* {
		try_files {path} {path}/ {path}/index.html /nw/
	}
	handle /ma/* {
		try_files {path} {path}/ {path}/index.html /ma/
	}
	handle /moodle/* {
		php_fastcgi 127.0.0.1:9000
		try_files {path} {path}/ {path}/index.php /moodle/
	}
	handle {
		try_files {path} {path}/ {path}/index.html / # remove last / if you want to show 404.html on error
	}
}

http:// {
	import capacic
	log {
		output file /etc/caddy/log/caddy.log
	}
}

localhost {
	# Set this path to your site's directory.
	import capacic
	#tls {
	#	dns cloudflare xxx
	#}
	log {
		output file /etc/caddy/log/caddy.log
	}
}
