From 7ffc9e6f5003cef87e603cbf0821ecc6c2a7f46e Mon Sep 17 00:00:00 2001 From: Nash Gadre Date: Thu, 7 Nov 2024 18:29:04 -0500 Subject: [PATCH] handle wildcard domains --- fast-server/server/server.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/fast-server/server/server.go b/fast-server/server/server.go index 4694b36..36ddf11 100644 --- a/fast-server/server/server.go +++ b/fast-server/server/server.go @@ -113,7 +113,17 @@ func (s *Server) setupRoutes() { var matchedDomain config.Domain var matchedName string for domainName, domain := range domainMap { - if strings.HasSuffix(host, domainName) { + // Handle wildcard domains + if strings.HasPrefix(domainName, "*.") { + suffix := domainName[1:] // Remove the * + if strings.HasSuffix(host, suffix) { + if len(suffix) > len(matchedName) { + matchedDomain = domain + matchedName = suffix + } + } + } else if strings.HasSuffix(host, domainName) { + // Handle exact domain matches if len(domainName) > len(matchedName) { matchedDomain = domain matchedName = domainName