repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

commit
263937b
parent
3225b71
author
Eric Bower
date
2026-04-19 19:40:46 -0400 EDT
fix(pgs): cdn routing to correct place
1 files changed,  +9, -9
M cmd/pgs/cdn/main.go
+9, -9
 1@@ -63,7 +63,13 @@ func newProxyServe(logger *slog.Logger) *proxyServe {
 2 }
 3 
 4 func (p *proxyServe) ServeHTTP(w http.ResponseWriter, req *http.Request) {
 5-	target, _ := url.Parse(partialURL(req))
 6+	// Dial ash.pgs.sh but keep the original Host header so ash.pgs.sh
 7+	// can route the request to the correct subdomain (zmx.sh, etc.).
 8+	// Without the Host header, ash.pgs.sh serves its default vhost (HTML).
 9+	target, _ := url.Parse("https://ash.pgs.sh" + req.URL.Path)
10+	if req.URL.RawQuery != "" {
11+		target.RawQuery = req.URL.RawQuery
12+	}
13 	p.Logger.Info("proxying request to ash.pgs.sh", "url", target.String())
14 
15 	proxyReq := req.Clone(req.Context())
16@@ -72,6 +78,8 @@ func (p *proxyServe) ServeHTTP(w http.ResponseWriter, req *http.Request) {
17 	proxyReq.URL.Path = target.Path
18 	proxyReq.URL.RawQuery = target.RawQuery
19 	proxyReq.RequestURI = ""
20+	// Preserve the original Host header so ash.pgs.sh routes correctly.
21+	proxyReq.Host = req.Host
22 
23 	resp, err := p.transport.RoundTrip(proxyReq)
24 	if err != nil {
25@@ -122,11 +130,3 @@ func (c *cachedHttp) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
26 
27 	c.Cache.ServeHTTP(writer, req)
28 }
29-
30-func partialURL(r *http.Request) string {
31-	builder := strings.Builder{}
32-	// this service sits behind a proxy so we need to force it to https
33-	builder.WriteString("https://")
34-	builder.WriteString(r.Host)
35-	return builder.String()
36-}