added logging

This commit is contained in:
Steve Dudenhoeffer 2023-10-06 02:28:29 -04:00
parent ae18c0ea3b
commit a5e74338d4
2 changed files with 11 additions and 0 deletions

5
Dockerfile Normal file
View File

@ -0,0 +1,5 @@
FROM scratch
COPY proxy /proxy
ENTRYPOINT ["/proxy"]

View File

@ -2,6 +2,7 @@ package simpleproxy
import (
"io"
"log/slog"
"net/http"
"net/url"
)
@ -41,6 +42,9 @@ func (p *Proxy) ListenAndServe() error {
// ServeHTTP is the main handler for the proxy server.
// all requests here should be proxied to the server.
func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
logger := slog.Default().With("method", r.Method, "url", r.URL.String())
logger.Info("proxying request")
// all requests should be proxied to the server.
req, err := http.NewRequest(r.Method, p.ServerAddr+r.URL.String(), r.Body)
if err != nil {
@ -61,6 +65,8 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
logger = slog.Default().With("status", resp.StatusCode)
mirrorResponse(w, resp)
}