Skip to content

Commit 72bb8a6

Browse files
committed
refactor: further align template syntax
1 parent 01d14f0 commit 72bb8a6

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

nginx.tmpl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ proxy_set_header Proxy "";
562562

563563
{{- range $hostname, $vhost := $parsedVhosts }}
564564
{{- $vhost_data := when (hasKey $globals.vhosts $hostname) (get $globals.vhosts $hostname) (dict) }}
565-
{{- $paths := coalesce $vhost_data.paths (dict) }}
565+
{{- $paths := $vhost_data.paths | default (dict) }}
566566

567567
{{- if (empty $vhost) }}
568568
{{ $vhost = dict "/" (dict) }}
@@ -572,7 +572,7 @@ proxy_set_header Proxy "";
572572
{{- if (empty $vpath) }}
573573
{{- $vpath = dict "dest" "" "port" "default" }}
574574
{{- end }}
575-
{{- $dest := coalesce $vpath.dest "" }}
575+
{{- $dest := $vpath.dest | default "" }}
576576
{{- $port := when (hasKey $vpath "port") (toString $vpath.port) "default" }}
577577
{{- $path_data := when (hasKey $paths $path) (get $paths $path) (dict) }}
578578
{{- $path_ports := when (hasKey $path_data "ports") (get $path_data "ports") (dict) }}
@@ -613,12 +613,12 @@ proxy_set_header Proxy "";
613613
{{- end }}
614614

615615
{{- $vhost_data := when (hasKey $globals.vhosts $hostname) (get $globals.vhosts $hostname) (dict) }}
616-
{{- $paths := coalesce $vhost_data.paths (dict) }}
616+
{{- $paths := $vhost_data.paths | default (dict) }}
617617

618618
{{- $tmp_paths := groupByWithDefault $containers "Env.VIRTUAL_PATH" "/" }}
619619

620620
{{- range $path, $containers := $tmp_paths }}
621-
{{- $dest := or (first (groupByKeys $containers "Env.VIRTUAL_DEST")) "" }}
621+
{{- $dest := groupByKeys $containers "Env.VIRTUAL_DEST" | first | default "" }}
622622
{{- $port := "legacy" }}
623623
{{- $path_data := when (hasKey $paths $path) (get $paths $path) (dict) }}
624624
{{- $path_ports := when (hasKey $path_data "ports") (get $path_data "ports") (dict) }}
@@ -649,12 +649,12 @@ proxy_set_header Proxy "";
649649
{{- end }}
650650

651651
{{- /* Get the VIRTUAL_PROTO defined by containers w/ the same vhost-vpath, falling back to "http". */}}
652-
{{- $proto := trim (or (first (groupByKeys $vpath_containers "Env.VIRTUAL_PROTO")) "http") }}
652+
{{- $proto := groupByKeys $vpath_containers "Env.VIRTUAL_PROTO" | first | default "http" | trim }}
653653
{{- /* Get the NETWORK_ACCESS defined by containers w/ the same vhost, falling back to "external". */}}
654-
{{- $network_tag := or (first (groupByKeys $vpath_containers "Env.NETWORK_ACCESS")) "external" }}
654+
{{- $network_tag := groupByKeys $vpath_containers "Env.NETWORK_ACCESS" | first | default "external" }}
655655

656-
{{- $loadbalance := first (keys (groupByLabel $vpath_containers "com.github.nginx-proxy.nginx-proxy.loadbalance")) }}
657-
{{- $keepalive := coalesce (first (keys (groupByLabel $vpath_containers "com.github.nginx-proxy.nginx-proxy.keepalive"))) "disabled" }}
656+
{{- $loadbalance := groupByLabel $vpath_containers "com.github.nginx-proxy.nginx-proxy.loadbalance" | keys | first }}
657+
{{- $keepalive := groupByLabel $vpath_containers "com.github.nginx-proxy.nginx-proxy.keepalive" | keys | first | default "disabled" }}
658658

659659
{{- $upstream := $vhost_data.upstream_name }}
660660
{{- if (not (eq $path "/")) }}
@@ -672,14 +672,14 @@ proxy_set_header Proxy "";
672672
{{ $vhost_containers = concat $vhost_containers $vpath_containers }}
673673
{{- end }}
674674

675-
{{- $certName := first (groupByKeys $vhost_containers "Env.CERT_NAME") }}
675+
{{- $certName := groupByKeys $vhost_containers "Env.CERT_NAME" | first }}
676676
{{- $vhostCert := closest (dir "/etc/nginx/certs") (printf "%s.crt" $hostname) }}
677677
{{- $vhostCert = trimSuffix ".crt" $vhostCert }}
678678
{{- $vhostCert = trimSuffix ".key" $vhostCert }}
679679
{{- $cert := or $certName $vhostCert }}
680680
{{- $cert_ok := and (ne $cert "") (exists (printf "/etc/nginx/certs/%s.crt" $cert)) (exists (printf "/etc/nginx/certs/%s.key" $cert)) }}
681681

682-
{{- $enable_debug_endpoint := coalesce (groupByLabel $vhost_containers "com.github.nginx-proxy.nginx-proxy.debug-endpoint" | keys | first) $globals.config.enable_debug_endpoint | parseBool }}
682+
{{- $enable_debug_endpoint := groupByLabel $vhost_containers "com.github.nginx-proxy.nginx-proxy.debug-endpoint" | keys | first | default $globals.config.enable_debug_endpoint | parseBool }}
683683
{{- $default := eq $globals.config.default_host $hostname }}
684684
{{- $https_method := groupByKeys $vhost_containers "Env.HTTPS_METHOD" | first | default $globals.config.https_method }}
685685
{{- $enable_http_on_missing_cert := groupByKeys $vhost_containers "Env.ENABLE_HTTP_ON_MISSING_CERT" | first | default $globals.config.enable_http_on_missing_cert | parseBool }}
@@ -697,16 +697,16 @@ proxy_set_header Proxy "";
697697
{{- end }}
698698

699699
{{- /* Get the SERVER_TOKENS defined by containers w/ the same vhost, falling back to "". */}}
700-
{{- $server_tokens := trim (or (first (groupByKeys $vhost_containers "Env.SERVER_TOKENS")) "") }}
700+
{{- $server_tokens := groupByKeys $vhost_containers "Env.SERVER_TOKENS" | first | default "" | trim }}
701701

702702
{{- /* Get the SSL_POLICY defined by containers w/ the same vhost, falling back to empty string (use default). */}}
703-
{{- $ssl_policy := or (first (groupByKeys $vhost_containers "Env.SSL_POLICY")) "" }}
703+
{{- $ssl_policy := groupByKeys $vhost_containers "Env.SSL_POLICY" | first | default "" }}
704704

705705
{{- /* Get the HSTS defined by containers w/ the same vhost, falling back to "max-age=31536000". */}}
706706
{{- $hsts := groupByKeys $vhost_containers "Env.HSTS" | first | default $globals.config.hsts }}
707707

708708
{{- /* Get the VIRTUAL_ROOT By containers w/ use fastcgi root */}}
709-
{{- $vhost_root := or (first (groupByKeys $vhost_containers "Env.VIRTUAL_ROOT")) "/var/www/public" }}
709+
{{- $vhost_root := groupByKeys $vhost_containers "Env.VIRTUAL_ROOT" | first | default "/var/www/public" }}
710710

711711
{{- $vhost_data = merge $vhost_data (dict
712712
"cert" $cert

0 commit comments

Comments
 (0)