{% if matrix_mautrix_discord_container_labels_traefik_enabled %}
traefik.enable=true

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

traefik.http.services.matrix-mautrix-discord.loadbalancer.server.port=8080

{% if matrix_mautrix_discord_container_labels_avatar_proxy_enabled %}
############################################################
#                                                          #
# Avatar proxy                                             #
#                                                          #
############################################################

{% set middlewares = [] %}

{% if matrix_mautrix_discord_container_labels_traefik_path_prefix != '/' %}
traefik.http.middlewares.matrix-mautrix-discord-slashless-redirect.redirectregex.regex=({{ matrix_mautrix_discord_container_labels_traefik_path_prefix | quote }})$
traefik.http.middlewares.matrix-mautrix-discord-slashless-redirect.redirectregex.replacement=${1}/
{% set middlewares = middlewares + ['matrix-mautrix-discord-slashless-redirect'] %}
{% endif %}

{% if matrix_mautrix_discord_container_labels_traefik_path_prefix != '/' %}
traefik.http.middlewares.matrix-mautrix-discord-strip-prefix.stripprefix.prefixes={{ matrix_mautrix_discord_container_labels_traefik_path_prefix }}
{% set middlewares = middlewares + ['matrix-mautrix-discord-strip-prefix'] %}
{% endif %}

traefik.http.routers.matrix-mautrix-discord-avatar-proxy.rule={{ matrix_mautrix_discord_container_labels_avatar_proxy_traefik_rule }}

{% if matrix_mautrix_discord_container_labels_avatar_proxy_traefik_priority | int > 0 %}
traefik.http.routers.matrix-mautrix-discord-avatar-proxy.priority={{ matrix_mautrix_discord_container_labels_avatar_proxy_traefik_priority }}
{% endif %}

{% if middlewares | length > 0 %}
traefik.http.routers.matrix-mautrix-discord-avatar-proxy.middlewares={{ middlewares | join(',') }}
{% endif %}

traefik.http.routers.matrix-mautrix-discord-avatar-proxy.service=matrix-mautrix-discord
traefik.http.routers.matrix-mautrix-discord-avatar-proxy.entrypoints={{ matrix_mautrix_discord_container_labels_avatar_proxy_traefik_entrypoints }}

traefik.http.routers.matrix-mautrix-discord-avatar-proxy.tls={{ matrix_mautrix_discord_container_labels_avatar_proxy_traefik_tls | to_json }}
{% if matrix_mautrix_discord_container_labels_avatar_proxy_traefik_tls %}
traefik.http.routers.matrix-mautrix-discord-avatar-proxy.tls.certResolver={{ matrix_mautrix_discord_container_labels_avatar_proxy_traefik_tls_certResolver }}
{% endif %}

############################################################
#                                                          #
# /Avatar proxy                                            #
#                                                          #
############################################################
{% endif %}


{% endif %}

{{ matrix_mautrix_discord_container_labels_additional_labels }}
