repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
cfd74b9
parent
207b6d9
author
Antonio Mika
date
2022-08-01 16:39:06 +0000 UTC
Fixed custom domain routing logic
3 files changed,  +14, -15
M pastes/parser.go
+1, -0
1@@ -2,6 +2,7 @@ package pastes
2 
3 import (
4 	"bytes"
5+
6 	"github.com/alecthomas/chroma/formatters/html"
7 	"github.com/alecthomas/chroma/lexers"
8 	"github.com/alecthomas/chroma/styles"
M shared/router.go
+11, -9
 1@@ -38,15 +38,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-			if hostDomain != appDomain && strings.Contains(hostDomain, appDomain) {
 6-				subdomain = strings.TrimSuffix(hostDomain, fmt.Sprintf(".%s", appDomain))
 7-				if subdomain != "" {
 8-					curRoutes = subdomainRoutes
 9-				}
10-			} else {
11-				subdomain = GetCustomDomain(hostDomain)
12-				if subdomain != "" {
13-					curRoutes = subdomainRoutes
14+			if hostDomain != appDomain {
15+				if strings.Contains(hostDomain, appDomain) {
16+					subdomain = strings.TrimSuffix(hostDomain, fmt.Sprintf(".%s", appDomain))
17+					if subdomain != "" {
18+						curRoutes = subdomainRoutes
19+					}
20+				} else {
21+					subdomain = GetCustomDomain(hostDomain)
22+					if subdomain != "" {
23+						curRoutes = subdomainRoutes
24+					}
25 				}
26 			}
27 		}
M shared/util.go
+2, -6
 1@@ -40,7 +40,7 @@ func SanitizeFileExt(fname string) string {
 2 
 3 func KeyText(s ssh.Session) (string, error) {
 4 	if s.PublicKey() == nil {
 5-		return "", fmt.Errorf("Session doesn't have public key")
 6+		return "", fmt.Errorf("session doesn't have public key")
 7 	}
 8 	kb := base64.StdEncoding.EncodeToString(s.PublicKey().Marshal())
 9 	return fmt.Sprintf("%s %s", s.PublicKey().Type(), kb), nil
10@@ -76,11 +76,7 @@ func IsText(s string) bool {
11 
12 func IsExtAllowed(filename string, allowedExt []string) bool {
13 	ext := pathpkg.Ext(filename)
14-	if !slices.Contains(allowedExt, ext) {
15-		return false
16-	}
17-
18-	return true
19+	return slices.Contains(allowedExt, ext)
20 }
21 
22 // IsTextFile reports whether the file has a known extension indicating