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 {
6363 }
6464
6565 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+ }
6773 p.Logger.Info("proxying request to ash.pgs.sh", "url", target.String())
6874
6975 proxyReq := req.Clone(req.Context())
......@@ -72,6 +78,8 @@ func (p *proxyServe) ServeHTTP(w http.ResponseWriter, req *http.Request) {
7278 proxyReq.URL.Path = target.Path
7379 proxyReq.URL.RawQuery = target.RawQuery
7480 proxyReq.RequestURI = ""
81+ // Preserve the original Host header so ash.pgs.sh routes correctly.
82+ proxyReq.Host = req.Host
7583
7684 resp, err := p.transport.RoundTrip(proxyReq)
7785 if err != nil {
......@@ -122,11 +130,3 @@ func (c *cachedHttp) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
122130
123131 c.Cache.ServeHTTP(writer, req)
124132 }
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-}