From defc2d28011d736bd3b23b43a90e8756f3a3623f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barman?= Date: Tue, 29 Oct 2024 17:28:48 +0100 Subject: [PATCH] Add default response code --- README.md | 1 + molecule/reverse-proxy/converge.yml | 1 + molecule/reverse-proxy/files/Caddyfile.expected | 2 +- templates/Caddyfile.j2 | 4 ++++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 002e2f3..4197a1f 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ If you only want to install Caddy, you don't need to set any variables. If you w * `certificate_file`: You can set this variable if you want to provide the certificate by yourself (Optional). The certificate needs permissions `0640`, with root as Owner and Caddy as Group. * `certificate_key`: You can set this variable if you want to provide the certificate by yourself (Optional). * `domain`: The domain caddy should listen to. +* `default_response_code`: The code caddy will respond if the route is not defined. If not set, Caddy default behavior responds with code `200`. Afterwards, you can define a list of `routes` composing of the following values: diff --git a/molecule/reverse-proxy/converge.yml b/molecule/reverse-proxy/converge.yml index cb70736..24843ed 100644 --- a/molecule/reverse-proxy/converge.yml +++ b/molecule/reverse-proxy/converge.yml @@ -9,6 +9,7 @@ vars: caddy_sites: - domain: example.com + default_response_code: 404 routes: - path: '' reverse_proxy_destination: 192.168.50.2 diff --git a/molecule/reverse-proxy/files/Caddyfile.expected b/molecule/reverse-proxy/files/Caddyfile.expected index ffda6d7..2c186ce 100644 --- a/molecule/reverse-proxy/files/Caddyfile.expected +++ b/molecule/reverse-proxy/files/Caddyfile.expected @@ -40,7 +40,7 @@ example.com { respond @not_allowlist 404 } - + respond 404 } diff --git a/templates/Caddyfile.j2 b/templates/Caddyfile.j2 index 351b6b1..6b1fc84 100644 --- a/templates/Caddyfile.j2 +++ b/templates/Caddyfile.j2 @@ -58,6 +58,10 @@ {% if site.certificate_file is defined %} tls {{ site.certificate_file }} {{ site.certificate_key }} {%- endif %} + + {% if site.default_response_code is defined %} + respond {{ site.default_response_code }} + {%- endif %} } {% if (site.additional_forwarding_ports is defined) and (site.additional_forwarding_ports | length > 0) %}