From cafc0ac1f31d3a4ef4f30dcde6b314fb675ad065 Mon Sep 17 00:00:00 2001 From: Sudarshan Wadkar Date: Fri, 17 Apr 2020 23:50:57 +0530 Subject: [PATCH] Conditionally add www host to traefik router If the domain_name entered contains subdomains, e.g. `api.example.com` then do *not* add an additional `www.api.example.com` route to traefik If the user enters only the domain `example.com` then add the optional `www.example.com` Host to the traefik routers. --- .../compose/production/traefik/traefik.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.yml b/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.yml index 960d1ac2e..3f6d80721 100644 --- a/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.yml +++ b/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.yml @@ -28,7 +28,11 @@ certificatesResolvers: http: routers: web-router: + {%- if len(cookiecutter.domain_name.split('.')) == 2 %} rule: "Host(`{{ cookiecutter.domain_name }}`) || Host(`www.{{ cookiecutter.domain_name }}`)" + {% else %} + rule: "Host(`{{ cookiecutter.domain_name }}`)" + {%- endif %} entryPoints: - web middlewares: @@ -37,7 +41,11 @@ http: service: django web-secure-router: + {%- if len(cookiecutter.domain_name.split('.')) == 2 %} rule: "Host(`{{ cookiecutter.domain_name }}`) || Host(`www.{{ cookiecutter.domain_name }}`)" + {% else %} + rule: "Host(`{{ cookiecutter.domain_name }}`)" + {%- endif %} entryPoints: - web-secure middlewares: