infrastructure/playbooks/templates/caddy_site.conf.j2

46 lines
1.2 KiB
Text
Raw Normal View History

2024-09-26 22:02:36 +00:00
{%- macro caddy_site_hsts(svc, for_www) -%}
{%- if svc.hsts|default(false) and (svc.www_domain|default(false) == for_www) -%}
{{ 'header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload"' if svc.hsts|default(false) }}
{%- endif -%}
{%- endmacro -%}
{% macro caddy_site(svc) %}
{%- for domain in svc.additional_domains|default([]) %}
{{ domain }},
{% endfor -%}
{{ "www." + svc.domain if svc.www_domain|default(false) else svc.domain }} {
import default
{{ caddy_site_hsts(svc, false) }}
{{ svc.caddy_extra | indent(width='\t', first=True) if svc.caddy_extra|default(false) }}
{% if svc.caddy_default|default(true) %}
handle {
{% if svc.faas_function|default(false) %}
import faas {{ svc.faas_function }}
{% elif svc.redirect|default(false) %}
redir "{{ svc.redirect }}"
{% else %}
2024-10-13 19:48:04 +00:00
reverse_proxy {{ svc.docker_host|default(role_name) }}:{{ svc.port }}
2024-09-26 22:02:36 +00:00
{% endif %}
}
{% endif %}
}
{% if svc.www_domain|default(false) %}
{{ svc.domain }} {
import default
{{ caddy_site_hsts(svc, true) }}
redir https://www.{{ svc.domain }}{uri}
}
{% endif %}
{% endmacro -%}
2024-10-07 21:58:56 +00:00
{% if svc.domain|default(false) %}
2024-09-26 22:02:36 +00:00
{{ caddy_site(svc) }}
2024-10-07 21:58:56 +00:00
{% endif %}
2024-09-26 22:02:36 +00:00
{%- for extra_svc in svc.extra_svcs|default([]) %}
{{ caddy_site(extra_svc) }}
{% endfor %}