From dce7663b691f88cac3e44da185aaec333377f0c7 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Wed, 16 Oct 2024 23:16:48 +0200 Subject: [PATCH] refactor: remove duplicate code --- nginx.tmpl | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/nginx.tmpl b/nginx.tmpl index c7b5b2d..6b2a99e 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -350,8 +350,8 @@ upstream {{ $vpath.upstream }} { } {{- end }} -{{- /* debug "endpoint" response template */}} -{{- define "debug_response" }} +{{- /* debug "endpoint" location template */}} +{{- define "debug_location" }} {{- $debug_paths := dict }} {{- range $path, $vpath := .VHost.paths }} {{- $tmp_port := dict }} @@ -382,8 +382,11 @@ upstream {{ $vpath.upstream }} { ) "vhost" $debug_vhost }} - - {{- toJson $debug_response }} + + location /nginx-proxy-debug { + default_type application/json; + return 200 '{{ toJson $debug_response }}'; + } {{- end }} {{- define "access_log" }} @@ -826,10 +829,7 @@ server { {{- end }} {{- if $vhost.enable_debug_endpoint }} - location /nginx-proxy-debug { - default_type application/json; - return 200 '{{- template "debug_response" (dict "GlobalConfig" $globals.config "Hostname" $hostname "VHost" $vhost) }}'; - } + {{ template "debug_location" (dict "GlobalConfig" $globals.config "Hostname" $hostname "VHost" $vhost) }} {{- end }} location / { @@ -949,10 +949,7 @@ server { {{- end }} {{- if $vhost.enable_debug_endpoint }} - location /nginx-proxy-debug { - default_type application/json; - return 200 '{{- template "debug_response" (dict "GlobalConfig" $globals.config "Hostname" $hostname "VHost" $vhost) }}'; - } + {{ template "debug_location" (dict "GlobalConfig" $globals.config "Hostname" $hostname "VHost" $vhost) }} {{- end }} {{- range $path, $vpath := $vhost.paths }}