{% if matrix_dendrite_container_labels_traefik_enabled %}
traefik.enable=true

{% if matrix_dendrite_container_labels_traefik_docker_network %}
traefik.docker.network={{ matrix_dendrite_container_labels_traefik_docker_network }}
{% endif %}

traefik.http.services.matrix-dendrite.loadbalancer.server.port={{ matrix_dendrite_http_bind_port }}


{% if matrix_dendrite_container_labels_public_client_root_enabled %}
############################################################
#                                                          #
# Public Root path (/)                                     #
#                                                          #
############################################################

{% set client_root_middlewares = [] %}

{% if matrix_dendrite_container_labels_public_client_root_redirection_enabled %}
{% set client_root_middlewares = client_root_middlewares + ['matrix-dendrite-client-root-redirect'] %}
traefik.http.middlewares.matrix-dendrite-client-root-redirect.redirectregex.regex=(.*)
traefik.http.middlewares.matrix-dendrite-client-root-redirect.redirectregex.replacement={{ matrix_dendrite_container_labels_public_client_root_redirection_url }}
{% endif %}

traefik.http.routers.matrix-dendrite-public-client-root.rule={{ matrix_dendrite_container_labels_public_client_root_traefik_rule }}

traefik.http.routers.matrix-dendrite-public-client-root.middlewares={{ client_root_middlewares | join(',') }}

{% if matrix_dendrite_container_labels_public_client_root_traefik_priority | int > 0 %}
traefik.http.routers.matrix-dendrite-public-client-root.priority={{ matrix_dendrite_container_labels_public_client_root_traefik_priority }}
{% endif %}

traefik.http.routers.matrix-dendrite-public-client-root.service=matrix-dendrite
traefik.http.routers.matrix-dendrite-public-client-root.entrypoints={{ matrix_dendrite_container_labels_public_client_root_traefik_entrypoints }}
traefik.http.routers.matrix-dendrite-public-client-root.tls={{ matrix_dendrite_container_labels_public_client_root_traefik_tls | to_json }}

{% if matrix_dendrite_container_labels_public_client_root_traefik_tls %}
traefik.http.routers.matrix-dendrite-public-client-root.tls.certResolver={{ matrix_dendrite_container_labels_public_client_root_traefik_tls_certResolver }}
{% endif %}

############################################################
#                                                          #
# /Public Root path (/)                                    #
#                                                          #
############################################################
{% endif %}


{% if matrix_dendrite_container_labels_public_client_api_enabled %}
############################################################
#                                                          #
# Public Client-API (/_matrix)                             #
#                                                          #
############################################################

traefik.http.routers.matrix-dendrite-public-client-api.rule={{ matrix_dendrite_container_labels_public_client_api_traefik_rule }}

{% if matrix_dendrite_container_labels_public_client_api_traefik_priority | int > 0 %}
traefik.http.routers.matrix-dendrite-public-client-api.priority={{ matrix_dendrite_container_labels_public_client_api_traefik_priority }}
{% endif %}

traefik.http.routers.matrix-dendrite-public-client-api.service=matrix-dendrite
traefik.http.routers.matrix-dendrite-public-client-api.entrypoints={{ matrix_dendrite_container_labels_public_client_api_traefik_entrypoints }}
traefik.http.routers.matrix-dendrite-public-client-api.tls={{ matrix_dendrite_container_labels_public_client_api_traefik_tls | to_json }}

{% if matrix_dendrite_container_labels_public_client_api_traefik_tls %}
traefik.http.routers.matrix-dendrite-public-client-api.tls.certResolver={{ matrix_dendrite_container_labels_public_client_api_traefik_tls_certResolver }}
{% endif %}

############################################################
#                                                          #
# /Public Client-API (/_matrix)                            #
#                                                          #
############################################################
{% endif %}


{% if matrix_dendrite_container_labels_internal_client_api_enabled %}
############################################################
#                                                          #
# Internal Client-API (/_matrix)                           #
#                                                          #
############################################################

traefik.http.routers.matrix-dendrite-internal-client-api.rule={{ matrix_dendrite_container_labels_internal_client_api_traefik_rule }}

{% if matrix_dendrite_container_labels_internal_client_api_traefik_priority | int > 0 %}
traefik.http.routers.matrix-dendrite-internal-client-api.priority={{ matrix_dendrite_container_labels_internal_client_api_traefik_priority }}
{% endif %}

traefik.http.routers.matrix-dendrite-internal-client-api.service=matrix-dendrite
traefik.http.routers.matrix-dendrite-internal-client-api.entrypoints={{ matrix_dendrite_container_labels_internal_client_api_traefik_entrypoints }}

############################################################
#                                                          #
# /Internal Client-API (/_matrix)                          #
#                                                          #
############################################################
{% endif %}


{% if matrix_dendrite_container_labels_public_client_synapse_admin_api_enabled %}
############################################################
#                                                          #
# Public Synapse Admin API (/_synapse/admin)               #
#                                                          #
############################################################

traefik.http.routers.matrix-dendrite-public-client-synapse-admin-api.rule={{ matrix_dendrite_container_labels_public_client_synapse_admin_api_traefik_rule }}

{% if matrix_dendrite_container_labels_public_client_synapse_admin_api_traefik_priority | int > 0 %}
traefik.http.routers.matrix-dendrite-public-client-synapse-admin-api.priority={{ matrix_dendrite_container_labels_public_client_synapse_admin_api_traefik_priority }}
{% endif %}

traefik.http.routers.matrix-dendrite-public-client-synapse-admin-api.service=matrix-dendrite
traefik.http.routers.matrix-dendrite-public-client-synapse-admin-api.entrypoints={{ matrix_dendrite_container_labels_public_client_synapse_admin_api_traefik_entrypoints }}
traefik.http.routers.matrix-dendrite-public-client-synapse-admin-api.tls={{ matrix_dendrite_container_labels_public_client_synapse_admin_api_traefik_tls | to_json }}

{% if matrix_dendrite_container_labels_public_client_synapse_admin_api_traefik_tls %}
traefik.http.routers.matrix-dendrite-public-client-synapse-admin-api.tls.certResolver={{ matrix_dendrite_container_labels_public_client_synapse_admin_api_traefik_tls_certResolver }}
{% endif %}

############################################################
#                                                          #
# /Public Synapse Admin API (/_synapse/admin)              #
#                                                          #
############################################################
{% endif %}


{% if matrix_dendrite_container_labels_public_client_dendrite_admin_api_enabled %}
############################################################
#                                                          #
# Public Dendrite Admin API (/_dendrite/admin)             #
#                                                          #
############################################################

traefik.http.routers.matrix-dendrite-public-client-synapse-admin-api.rule={{ matrix_dendrite_container_labels_public_client_dendrite_admin_api_traefik_rule }}

{% if matrix_dendrite_container_labels_public_client_dendrite_admin_api_traefik_priority | int > 0 %}
traefik.http.routers.matrix-dendrite-public-client-synapse-admin-api.priority={{ matrix_dendrite_container_labels_public_client_dendrite_admin_api_traefik_priority }}
{% endif %}

traefik.http.routers.matrix-dendrite-public-client-synapse-admin-api.service=matrix-dendrite
traefik.http.routers.matrix-dendrite-public-client-synapse-admin-api.entrypoints={{ matrix_dendrite_container_labels_public_client_dendrite_admin_api_traefik_entrypoints }}
traefik.http.routers.matrix-dendrite-public-client-synapse-admin-api.tls={{ matrix_dendrite_container_labels_public_client_dendrite_admin_api_traefik_tls | to_json }}

{% if matrix_dendrite_container_labels_public_client_dendrite_admin_api_traefik_tls %}
traefik.http.routers.matrix-dendrite-public-client-synapse-admin-api.tls.certResolver={{ matrix_dendrite_container_labels_public_client_dendrite_admin_api_traefik_tls_certResolver }}
{% endif %}

############################################################
#                                                          #
# /Public Dendrite Admin API (/_dendrite/admin)            #
#                                                          #
############################################################
{% endif %}


{% if matrix_dendrite_container_labels_public_federation_api_enabled %}
############################################################
#                                                          #
# Public Federation-API (/_matrix)                         #
#                                                          #
############################################################

traefik.http.routers.matrix-dendrite-public-federation-api.rule={{ matrix_dendrite_container_labels_public_federation_api_traefik_rule }}

{% if matrix_dendrite_container_labels_public_federation_api_traefik_priority | int > 0 %}
traefik.http.routers.matrix-dendrite-public-federation-api.priority={{ matrix_dendrite_container_labels_public_federation_api_traefik_priority }}
{% endif %}

traefik.http.routers.matrix-dendrite-public-federation-api.service=matrix-dendrite
traefik.http.routers.matrix-dendrite-public-federation-api.entrypoints={{ matrix_dendrite_container_labels_public_federation_api_traefik_entrypoints }}
traefik.http.routers.matrix-dendrite-public-federation-api.tls={{ matrix_dendrite_container_labels_public_federation_api_traefik_tls | to_json }}

{% if matrix_dendrite_container_labels_public_federation_api_traefik_tls %}
traefik.http.routers.matrix-dendrite-public-federation-api.tls.certResolver={{ matrix_dendrite_container_labels_public_federation_api_traefik_tls_certResolver }}
{% endif %}

############################################################
#                                                          #
# /Public Federation-API (/_matrix)                        #
#                                                          #
############################################################
{% endif %}


{% if matrix_dendrite_container_labels_public_metrics_enabled %}
############################################################
#                                                          #
# Public Metrics                                           #
#                                                          #
############################################################

{% set metrics_middlewares = [] %}

{% if matrix_dendrite_container_labels_public_metrics_middleware_basic_auth_enabled %}
{% set metrics_middlewares = metrics_middlewares + ['matrix-dendrite-metrics-basic-auth'] %}
traefik.http.middlewares.matrix-dendrite-metrics-basic-auth.basicauth.users={{ matrix_dendrite_container_labels_public_metrics_middleware_basic_auth_users }}
{% endif %}

{% set metrics_middlewares = metrics_middlewares + ['matrix-dendrite-metrics-replacepath'] %}
traefik.http.middlewares.matrix-dendrite-metrics-replacepath.replacepath.path=/metrics

traefik.http.routers.matrix-dendrite-metrics.rule={{ matrix_dendrite_container_labels_public_metrics_traefik_rule }}

{% if metrics_middlewares | length > 0 %}
traefik.http.routers.matrix-dendrite-metrics.middlewares={{ metrics_middlewares | join(',') }}
{% endif %}

{% if matrix_dendrite_container_labels_public_metrics_traefik_priority | int > 0 %}
traefik.http.routers.matrix-dendrite-metrics.priority={{ matrix_dendrite_container_labels_public_metrics_traefik_priority }}
{% endif %}

traefik.http.routers.matrix-dendrite-metrics.service=matrix-dendrite
traefik.http.routers.matrix-dendrite-metrics.entrypoints={{ matrix_dendrite_container_labels_public_metrics_traefik_entrypoints }}

traefik.http.routers.matrix-dendrite-metrics.tls={{ matrix_dendrite_container_labels_public_metrics_traefik_tls | to_json }}
{% if matrix_dendrite_container_labels_public_metrics_traefik_tls %}
traefik.http.routers.matrix-dendrite-metrics.tls.certResolver={{ matrix_dendrite_container_labels_public_metrics_traefik_tls_certResolver }}
{% endif %}

############################################################
#                                                          #
# /Public Metrics                                          #
#                                                          #
############################################################
{% endif %}


{% endif %}

{{ matrix_dendrite_container_labels_additional_labels }}
