From a2c6d172266dfd1919ce1cee90dd1536c9b87da3 Mon Sep 17 00:00:00 2001 From: fujiwara Date: Tue, 23 Jan 2024 14:14:21 +0900 Subject: [PATCH] fix invalid warning Supress invalid warning when multiple listen.http sections defined. --- reverseproxy.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/reverseproxy.go b/reverseproxy.go index 4cf04e5..413f9d0 100644 --- a/reverseproxy.go +++ b/reverseproxy.go @@ -208,15 +208,14 @@ func (r *ReverseProxy) AddSubdomain(subdomain string, ipaddress string, targetPo } // create reverse proxy + proxy := false for _, v := range r.cfg.Listen.HTTP { - if v.TargetPort != targetPort { - if !r.cfg.localMode { - log.Printf("[warn] target port %d is not defined in config.", targetPort) - continue - } + if (v.TargetPort != targetPort) && !r.cfg.localMode { + continue // local mode allows any port } if ph.exists(v.ListenPort, addr) { + proxy = true continue } destUrlString := "http://" + addr @@ -237,8 +236,14 @@ func (r *ReverseProxy) AddSubdomain(subdomain string, ipaddress string, targetPo } handler.Transport = tp ph.add(v.ListenPort, addr, handler) + proxy = true log.Printf("[info] add subdomain: %s:%d -> %s", subdomain, v.ListenPort, addr) } + if !proxy { + log.Printf("[warn] proxy of subdomain %s(target port %d) is not created. define target port in listen.http[]", subdomain, targetPort) + return + } + r.domainMap[subdomain] = ph for _, name := range r.domains { if name == subdomain {