I have a reverse proxy, which I wrote. It simply intercepts requests to validate auth then forwards to the origin server. The problem is that none of the assets are rendering properly, but the site loads.
Prometheus Server (My application behind the reverse proxy)
Comparing the response data with and without my reverse proxy, I can see that when it works as expected, the content-type is different.
However, when I'm using the reverse proxy and I hit the links directly (i.e - the logo which isn't loading), I can get the image itself to render fine.
What could I be missing? I assume it's something simple, but I can't figure it out.
// ReverseProxy is a blind forwarding reverse proxy that is intended to run
// after all registered middleware
func ReverseProxy(w http.ResponseWriter, req *http.Request) {
// This represents the origin server, which would be loaded dynamically from the deployment config or
// external environment variables, config map, secrets vault, etc
for key, ele := range mw {
fmt.Printf("Invoking middleware: %s\n", key)
err := ele(w, req)
if err != nil {
unauthorizedPage(w, req)
return
}
}
fmt.Printf("\n\n")
// Maps to internal container host (multi-container pod)
host := "localhost"
port, _ := strconv.Atoi(os.Getenv("POST_AUTH_TARGET_PORT"))
originSvr, err := url.Parse(fmt.Sprintf("http://%s:%d", host, port))
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, req)
return
}
req.Header.Add("X-Forwarded-Host", req.Host)
req.Header.Add("X-Origin-Host", originSvr.Host)
req.Host = originSvr.Host
req.URL.Host = originSvr.Host
req.URL.Scheme = originSvr.Scheme
req.RequestURI = ""
originResp, err := http.DefaultClient.Do(req)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, req)
return
}
w.WriteHeader(originResp.StatusCode)
io.Copy(w, originResp.Body)
}
