From daef2b7f1377b09343a8b3072e10e66618bfda9f Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 30 Jul 2021 11:50:10 +0200 Subject: [PATCH] Add conditional default subdomain setting to proxy If a domain has been declared for the host, the upstream file will proxy at a subdomain named for the stack it proxies to, otherwise it will do the same for the path. --- group_vars/testing.yml | 1 - .../whoami/templates/whoami_upstream.json.j2 | 35 ++++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/group_vars/testing.yml b/group_vars/testing.yml index 458184e..2f99c5c 100644 --- a/group_vars/testing.yml +++ b/group_vars/testing.yml @@ -5,4 +5,3 @@ docker_swarm_advertise_addr: eth1 caddy_use_debug: yes caddy_use_https: no caddy_tls_use_staging: yes -caddy_create_test_file_server: yes diff --git a/roles/whoami/templates/whoami_upstream.json.j2 b/roles/whoami/templates/whoami_upstream.json.j2 index de14a2f..f272643 100644 --- a/roles/whoami/templates/whoami_upstream.json.j2 +++ b/roles/whoami/templates/whoami_upstream.json.j2 @@ -1,13 +1,30 @@ { - "@id": "{{ stack.name }}_upstream", - "handle": [ - { - "handler": "reverse_proxy", - "upstreams": [ + "@id": "{{ stack.name }}_upstream", +{% if domain is not undefined and not none %} + "match": [ { - "dial": "{{ stack.name }}_app:80" + "host": [ + "{{ stack.name }}.{{ domain }}" + ] } - ] - } - ] + ], +{% else %} + "match": [ + { + "path": [ + "/{{ stack.name }}*" + ] + } + ], +{% endif %} + "handle": [ + { + "handler": "reverse_proxy", + "upstreams": [ + { + "dial": "{{ stack.name }}_app:80" + } + ] + } + ] }