1
0
Fork 0
mirror of https://github.com/nginx-proxy/nginx-proxy synced 2024-04-27 12:25:25 +02:00

style: improve template readability

This commit is contained in:
Nicolas Duchon 2022-12-28 00:53:25 +01:00
parent 99ee61a15d
commit 9dbb1b4153

View File

@ -107,7 +107,13 @@ upstream {{ .Upstream }} {
{{ end }}
{{ range $knownNetwork := $networks }}
{{ range $containerNetwork := sortObjectsByKeysAsc $container.Networks "Name" }}
{{ if (and (ne $containerNetwork.Name "ingress") (or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host"))) }}
{{ if (and
(ne $containerNetwork.Name "ingress")
(or
(eq $knownNetwork.Name $containerNetwork.Name)
(eq $knownNetwork.Name "host")
)
)}}
## Can be connected with "{{ $containerNetwork.Name }}" network
{{ if $address }}
{{/* If we got the containers from swarm and this container's port is published to host, use host IP:PORT */}}
@ -289,13 +295,23 @@ server {
{{ if eq $nPaths 0 }}
# {{ $host }}
{{ template "upstream" (dict "Upstream" $upstream_name "Containers" $containers "Networks" $CurrentContainer.Networks "Debug" $debug_all) }}
{{ template "upstream" (dict
"Upstream" $upstream_name
"Containers" $containers
"Networks" $CurrentContainer.Networks
"Debug" $debug_all
)}}
{{ else }}
{{ range $path, $containers := $paths }}
{{ $sum := sha1 $path }}
{{ $upstream := printf "%s-%s" $upstream_name $sum }}
# {{ $host }}{{ $path }}
{{ template "upstream" (dict "Upstream" $upstream "Containers" $containers "Networks" $CurrentContainer.Networks "Debug" $debug_all) }}
{{ template "upstream" (dict
"Upstream" $upstream
"Containers" $containers
"Networks" $CurrentContainer.Networks
"Debug" $debug_all
)}}
{{ end }}
{{ end }}
@ -340,7 +356,12 @@ server {
"AccessLog" $access_log
}}
{{ $is_https := (and (ne $https_method "nohttps") (ne $cert "") (exists (printf "/etc/nginx/certs/%s.crt" $cert)) (exists (printf "/etc/nginx/certs/%s.key" $cert))) }}
{{ $is_https := (and
(ne $https_method "nohttps")
(ne $cert "")
(exists (printf "/etc/nginx/certs/%s.crt" $cert))
(exists (printf "/etc/nginx/certs/%s.key" $cert))
)}}
{{ if $is_https }}
@ -412,7 +433,15 @@ server {
{{/* Get the NETWORK_ACCESS defined by containers w/ the same vhost, falling back to "external" */}}
{{ $network_tag := or (first (groupByKeys $containers "Env.NETWORK_ACCESS")) "external" }}
{{ template "location" (dict "Path" "/" "Proto" $proto "Upstream" $upstream_name "Host" $host "VhostRoot" $vhost_root "Dest" "" "NetworkTag" $network_tag) }}
{{ template "location" (dict
"Path" "/"
"Proto" $proto
"Upstream" $upstream_name
"Host" $host
"VhostRoot" $vhost_root
"Dest" ""
"NetworkTag" $network_tag
)}}
{{ else }}
{{ range $path, $container := $paths }}
{{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost-vpath, falling back to "http" */}}
@ -423,7 +452,15 @@ server {
{{ $sum := sha1 $path }}
{{ $upstream := printf "%s-%s" $upstream_name $sum }}
{{ $dest := (or (first (groupByKeys $container "Env.VIRTUAL_DEST")) "") }}
{{ template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "VhostRoot" $vhost_root "Dest" $dest "NetworkTag" $network_tag) }}
{{ template "location" (dict
"Path" $path
"Proto" $proto
"Upstream" $upstream
"Host" $host
"VhostRoot" $vhost_root
"Dest" $dest
"NetworkTag" $network_tag
)}}
{{ end }}
{{ if (not (contains $paths "/")) }}
location / {
@ -455,7 +492,15 @@ server {
{{/* Get the NETWORK_ACCESS defined by containers w/ the same vhost, falling back to "external" */}}
{{ $network_tag := or (first (groupByKeys $containers "Env.NETWORK_ACCESS")) "external" }}
{{ template "location" (dict "Path" "/" "Proto" $proto "Upstream" $upstream_name "Host" $host "VhostRoot" $vhost_root "Dest" "" "NetworkTag" $network_tag) }}
{{ template "location" (dict
"Path" "/"
"Proto" $proto
"Upstream" $upstream_name
"Host" $host
"VhostRoot" $vhost_root
"Dest" ""
"NetworkTag" $network_tag
)}}
{{ else }}
{{ range $path, $container := $paths }}
{{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost-vpath, falling back to "http" */}}
@ -466,7 +511,15 @@ server {
{{ $sum := sha1 $path }}
{{ $upstream := printf "%s-%s" $upstream_name $sum }}
{{ $dest := (or (first (groupByKeys $container "Env.VIRTUAL_DEST")) "") }}
{{ template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "VhostRoot" $vhost_root "Dest" $dest "NetworkTag" $network_tag) }}
{{ template "location" (dict
"Path" $path
"Proto" $proto
"Upstream" $upstream
"Host" $host
"VhostRoot" $vhost_root
"Dest" $dest
"NetworkTag" $network_tag
)}}
{{ end }}
{{ if (not (contains $paths "/")) }}
location / {
@ -476,7 +529,11 @@ server {
{{ end }}
}
{{ if (and (not $is_https) (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }}
{{ if (and
(not $is_https)
(exists "/etc/nginx/certs/default.crt")
(exists "/etc/nginx/certs/default.key")
)}}
server {
{{ template "server_config" (deepCopy $baseServerConfig | mustMerge (dict
"SSL" true