From cafc0ac1f31d3a4ef4f30dcde6b314fb675ad065 Mon Sep 17 00:00:00 2001 From: Sudarshan Wadkar Date: Fri, 17 Apr 2020 23:50:57 +0530 Subject: [PATCH 1/4] 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: From ab93e28c888588bc4ac41062386c0238745e796e Mon Sep 17 00:00:00 2001 From: Sudarshan Wadkar Date: Fri, 17 Apr 2020 23:57:15 +0530 Subject: [PATCH 2/4] Update contributors --- CONTRIBUTORS.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 280a9f4f1..86b529eb7 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -206,6 +206,7 @@ Listed in alphabetical order. Srinivas Nyayapati `@shireenrao`_ stepmr `@stepmr`_ Steve Steiner `@ssteinerX`_ + Sudarshan Wadkar `@wadkar`_ Sule Marshall `@suledev`_ Tano Abeleyra `@tanoabeleyra`_ Taylor Baldwin @@ -393,6 +394,7 @@ Listed in alphabetical order. .. _@umrashrf: https://github.com/umrashrf .. _@viviangb: https://github.com/viviangb .. _@vladdoster: https://github.com/vladdoster +.. _@wadkar: https://github.com/wadkar .. _@xpostudio4: https://github.com/xpostudio4 .. _@yrchen: https://github.com/yrchen .. _@yunti: https://github.com/yunti From 4021286be0ba0d857d03f93212a3dd6e946ece01 Mon Sep 17 00:00:00 2001 From: Sudarshan Wadkar Date: Sat, 18 Apr 2020 00:13:12 +0530 Subject: [PATCH 3/4] Add condition to include .co.XX TLDs This is best effort checking of domain names and creating the traefik rules. These two checks should cover most of the use cases. --- .../compose/production/traefik/traefik.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.yml b/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.yml index 3f6d80721..5ff2e3636 100644 --- a/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.yml +++ b/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.yml @@ -26,9 +26,10 @@ certificatesResolvers: entryPoint: web http: + {%- set domain_dots = cookiecutter.domain_name.count('.') %} routers: web-router: - {%- if len(cookiecutter.domain_name.split('.')) == 2 %} + {%- if domain_dots == 1 or (domain_dots == 2 and '.co.' in cookiecutter.domain_name) %} rule: "Host(`{{ cookiecutter.domain_name }}`) || Host(`www.{{ cookiecutter.domain_name }}`)" {% else %} rule: "Host(`{{ cookiecutter.domain_name }}`)" @@ -41,7 +42,7 @@ http: service: django web-secure-router: - {%- if len(cookiecutter.domain_name.split('.')) == 2 %} + {%- if domain_dots == 1 or (domain_dots == 2 and '.co.' in cookiecutter.domain_name) %} rule: "Host(`{{ cookiecutter.domain_name }}`) || Host(`www.{{ cookiecutter.domain_name }}`)" {% else %} rule: "Host(`{{ cookiecutter.domain_name }}`)" From 9cf47898f41b135b390f5e27c9c52b4a85fe6a8d Mon Sep 17 00:00:00 2001 From: Sudarshan Wadkar Date: Fri, 24 Apr 2020 14:00:27 +0530 Subject: [PATCH 4/4] Only consider TLDs while adding `www` route Instead of checking for `.co.XX` on best effort basis, we only check for the single dot in the domain_name indicating no subdomain usage. --- .../compose/production/traefik/traefik.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.yml b/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.yml index 5ff2e3636..cfd566a8d 100644 --- a/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.yml +++ b/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.yml @@ -26,10 +26,9 @@ certificatesResolvers: entryPoint: web http: - {%- set domain_dots = cookiecutter.domain_name.count('.') %} routers: web-router: - {%- if domain_dots == 1 or (domain_dots == 2 and '.co.' in cookiecutter.domain_name) %} + {%- if cookiecutter.domain_name.count('.') == 1 %} rule: "Host(`{{ cookiecutter.domain_name }}`) || Host(`www.{{ cookiecutter.domain_name }}`)" {% else %} rule: "Host(`{{ cookiecutter.domain_name }}`)" @@ -42,7 +41,7 @@ http: service: django web-secure-router: - {%- if domain_dots == 1 or (domain_dots == 2 and '.co.' in cookiecutter.domain_name) %} + {%- if cookiecutter.domain_name.count('.') == 1 %} rule: "Host(`{{ cookiecutter.domain_name }}`) || Host(`www.{{ cookiecutter.domain_name }}`)" {% else %} rule: "Host(`{{ cookiecutter.domain_name }}`)"