Commit 263937b
Eric Bower
·
2026-04-19 19:40:46 -0400 EDT
parent 3225b71
fix(pgs): cdn routing to correct place
1 files changed,
+9,
-9
+9,
-9
| ... | ... | @@ -63,7 +63,13 @@ func newProxyServe(logger *slog.Logger) *proxyServe { | |
| 63 | 63 | } | |
| 64 | 64 | ||
| 65 | 65 | func (p *proxyServe) ServeHTTP(w http.ResponseWriter, req *http.Request) { | |
| 66 | - | target, _ := url.Parse(partialURL(req)) | |
| 66 | + | // Dial ash.pgs.sh but keep the original Host header so ash.pgs.sh | |
| 67 | + | // can route the request to the correct subdomain (zmx.sh, etc.). | |
| 68 | + | // Without the Host header, ash.pgs.sh serves its default vhost (HTML). | |
| 69 | + | target, _ := url.Parse("https://ash.pgs.sh" + req.URL.Path) | |
| 70 | + | if req.URL.RawQuery != "" { | |
| 71 | + | target.RawQuery = req.URL.RawQuery | |
| 72 | + | } | |
| 67 | 73 | p.Logger.Info("proxying request to ash.pgs.sh", "url", target.String()) | |
| 68 | 74 | ||
| 69 | 75 | proxyReq := req.Clone(req.Context()) |
| ... | ... | @@ -72,6 +78,8 @@ func (p *proxyServe) ServeHTTP(w http.ResponseWriter, req *http.Request) { | |
| 72 | 78 | proxyReq.URL.Path = target.Path | |
| 73 | 79 | proxyReq.URL.RawQuery = target.RawQuery | |
| 74 | 80 | proxyReq.RequestURI = "" | |
| 81 | + | // Preserve the original Host header so ash.pgs.sh routes correctly. | |
| 82 | + | proxyReq.Host = req.Host | |
| 75 | 83 | ||
| 76 | 84 | resp, err := p.transport.RoundTrip(proxyReq) | |
| 77 | 85 | if err != nil { |
| ... | ... | @@ -122,11 +130,3 @@ func (c *cachedHttp) ServeHTTP(writer http.ResponseWriter, req *http.Request) { | |
| 122 | 130 | ||
| 123 | 131 | c.Cache.ServeHTTP(writer, req) | |
| 124 | 132 | } | |
| 125 | - | ||
| 126 | - | func partialURL(r *http.Request) string { | |
| 127 | - | builder := strings.Builder{} | |
| 128 | - | // this service sits behind a proxy so we need to force it to https | |
| 129 | - | builder.WriteString("https://") | |
| 130 | - | builder.WriteString(r.Host) | |
| 131 | - | return builder.String() | |
| 132 | - | } |