- commit
- 2c908e6
- parent
- 663da98
- author
- Eric Bower
- date
- 2025-06-16 10:24:27 -0400 EDT
fix(pgs): cdn manually proxy check handler
1 files changed,
+19,
-8
+19,
-8
1@@ -51,17 +51,28 @@ type cachedHttp struct {
2 }
3
4 func (c *cachedHttp) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
5- _ = c.handler.ServeHTTP(writer, req, func(w http.ResponseWriter, r *http.Request) error {
6- url, _ := url.Parse(fullURL(r))
7+ if req.URL.Path == "/_metrics" {
8+ promhttp.Handler().ServeHTTP(writer, req)
9+ return
10+ }
11
12- if req.URL.Path == "/_metrics" {
13- promhttp.Handler().ServeHTTP(writer, req)
14- return nil
15- }
16+ if req.URL.Path == "/check" {
17+ c.routes.Cfg.Logger.Info("proxying `/check` request to ash.pgs.sh", "query", req.URL.RawQuery)
18+ req, _ := http.NewRequest("GET", "https://ash.pgs.sh/check?"+req.URL.RawQuery, nil)
19+ req.Host = "pgs.sh"
20+ // reqDump, _ := httputil.DumpRequestOut(req, true)
21+ // fmt.Printf("REQUEST:\n%s", string(reqDump))
22
23- if req.URL.Path == "/check" {
24- url, _ = url.Parse("https://pgs.sh/check?" + r.URL.RawQuery)
25+ resp, err := http.DefaultClient.Do(req)
26+ if err != nil {
27+ c.routes.Cfg.Logger.Error("check request", "err", err)
28 }
29+ writer.WriteHeader(resp.StatusCode)
30+ return
31+ }
32+
33+ _ = c.handler.ServeHTTP(writer, req, func(w http.ResponseWriter, r *http.Request) error {
34+ url, _ := url.Parse(fullURL(r))
35
36 c.routes.Cfg.Logger.Info("proxying request to ash.pgs.sh", "url", url.String())
37 defaultTransport := http.DefaultTransport.(*http.Transport)