diff --git a/roles/custom/matrix-static-files/defaults/main.yml b/roles/custom/matrix-static-files/defaults/main.yml index b52e9540c..89fb02a33 100644 --- a/roles/custom/matrix-static-files/defaults/main.yml +++ b/roles/custom/matrix-static-files/defaults/main.yml @@ -57,6 +57,11 @@ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_priority matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_entrypoints: "{{ matrix_static_files_container_labels_traefik_entrypoints }}" matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_tls: "{{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_entrypoints != 'web' }}" matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_tls_certResolver: "{{ matrix_static_files_container_labels_traefik_tls_certResolver }}" # noqa var-naming +# Controls whether the compress middleware (https://doc.traefik.io/traefik/middlewares/http/compress/) will be enabled for this router. +# The web-server only compresses known file types and our /.well-known/matrix/* files have no file extension. +# As such, they are not being compressed there and we compress them at the Traefik level. +matrix_static_files_container_labels_well_known_matrix_endpoint_middleware_compress_enabled: true +matrix_static_files_container_labels_well_known_matrix_endpoint_middleware_compress_minResponseBodyBytes: 100 # noqa var-naming # Controls whether labels will be added that serve the base domain. # @@ -77,7 +82,6 @@ matrix_static_files_container_labels_base_domain_traefik_entrypoints: "{{ matrix matrix_static_files_container_labels_base_domain_traefik_tls: "{{ matrix_static_files_container_labels_base_domain_traefik_entrypoints != 'web' }}" matrix_static_files_container_labels_base_domain_traefik_tls_certResolver: "{{ matrix_static_files_container_labels_traefik_tls_certResolver }}" # noqa var-naming - # matrix_static_files_container_labels_additional_labels contains a multiline string with additional labels to add to the container label file. # See `../templates/labels.j2` for details. # diff --git a/roles/custom/matrix-static-files/templates/labels.j2 b/roles/custom/matrix-static-files/templates/labels.j2 index 6f49b4018..6b9c17b72 100644 --- a/roles/custom/matrix-static-files/templates/labels.j2 +++ b/roles/custom/matrix-static-files/templates/labels.j2 @@ -13,11 +13,19 @@ traefik.http.services.{{ matrix_static_files_ident }}.loadbalancer.server.port={ #} {% if matrix_static_files_container_labels_well_known_matrix_endpoint_enabled %} +{% set well_known_matrix_endpoint_middlewares = [] %} + +{% if matrix_static_files_container_labels_well_known_matrix_endpoint_middleware_compress_enabled %} traefik.http.middlewares.{{ matrix_static_files_ident }}-well-known-endpoint-compress.compress=true -traefik.http.middlewares.{{ matrix_static_files_ident }}-well-known-endpoint-compress.compress.minResponseBodyBytes=100 +traefik.http.middlewares.{{ matrix_static_files_ident }}-well-known-endpoint-compress.compress.minResponseBodyBytes={{ matrix_static_files_container_labels_well_known_matrix_endpoint_middleware_compress_minResponseBodyBytes }} +{% set well_known_matrix_endpoint_middlewares = well_known_matrix_endpoint_middlewares + [matrix_static_files_ident + '-well-known-endpoint-compress'] %} +{% endif %} traefik.http.routers.{{ matrix_static_files_ident }}-well-known-endpoint.rule={{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_rule }} -traefik.http.routers.{{ matrix_static_files_ident }}-well-known-endpoint.middlewares={{ matrix_static_files_ident }}-well-known-endpoint-compress + +{% if well_known_matrix_endpoint_middlewares | length > 0 %} +traefik.http.routers.{{ matrix_static_files_ident }}-well-known-endpoint.middlewares={{ well_known_matrix_endpoint_middlewares | join(',') }} +{% endif %} {% if matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_priority | int > 0 %} traefik.http.routers.{{ matrix_static_files_ident }}-well-known-endpoint.priority={{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_priority }}