- commit
- 975f3fb
- parent
- 805d258
- author
- Eric Bower
- date
- 2023-09-05 15:09:11 +0000 UTC
chore: add more logging for router
2 files changed,
+11,
-4
1@@ -11,13 +11,14 @@ import (
2 func CheckHandler(w http.ResponseWriter, r *http.Request) {
3 dbpool := GetDB(r)
4 cfg := GetCfg(r)
5+ logger := GetLogger(r)
6
7 if cfg.IsCustomdomains() {
8 hostDomain := r.URL.Query().Get("domain")
9 appDomain := strings.Split(cfg.ConfigCms.Domain, ":")[0]
10
11 if !strings.Contains(hostDomain, appDomain) {
12- subdomain := GetCustomDomain(hostDomain, cfg.Space)
13+ subdomain := GetCustomDomain(logger, hostDomain, cfg.Space)
14 if subdomain != "" {
15 u, err := dbpool.FindUserForName(subdomain)
16 if u != nil && err == nil {
1@@ -56,14 +56,17 @@ func CreateServe(routes []Route, subdomainRoutes []Route, cfg *ConfigSite, dbpoo
2 hostDomain := strings.ToLower(strings.Split(r.Host, ":")[0])
3 appDomain := strings.ToLower(strings.Split(cfg.ConfigCms.Domain, ":")[0])
4
5+ logger.Infof("servicing request with (hostDomain: %s, appDomain: %s)", hostDomain, appDomain)
6 if hostDomain != appDomain {
7 if strings.Contains(hostDomain, appDomain) {
8 subdomain = strings.TrimSuffix(hostDomain, fmt.Sprintf(".%s", appDomain))
9+ logger.Infof("servicing request with (subdomain: %s)", subdomain)
10 if subdomain != "" {
11 curRoutes = subdomainRoutes
12 }
13 } else {
14- subdomain = GetCustomDomain(hostDomain, cfg.Space)
15+ subdomain = GetCustomDomain(logger, hostDomain, cfg.Space)
16+ logger.Infof("servicing request with (custom domain %s)", subdomain)
17 if subdomain != "" {
18 curRoutes = subdomainRoutes
19 }
20@@ -138,9 +141,12 @@ func GetSubdomain(r *http.Request) string {
21 return r.Context().Value(ctxSubdomainKey{}).(string)
22 }
23
24-func GetCustomDomain(host string, space string) string {
25- records, err := net.LookupTXT(fmt.Sprintf("_%s.%s", space, host))
26+func GetCustomDomain(logger *zap.SugaredLogger, host string, space string) string {
27+ txt := fmt.Sprintf("_%s.%s", space, host)
28+ logger.Infof("looking up TXT (%s)", txt)
29+ records, err := net.LookupTXT(txt)
30 if err != nil {
31+ logger.Error(err)
32 return ""
33 }
34