feat: passthrough proxies
This commit is contained in:
@ -157,6 +157,7 @@ func (s *Server) run(parentCtx context.Context, addrs chan net.Addr, errs chan e
|
||||
director.ResponseTransformer(),
|
||||
),
|
||||
proxy.WithReverseProxyFactory(s.createReverseProxy),
|
||||
proxy.WithDefaultHandler(http.HandlerFunc(s.handleDefault)),
|
||||
)
|
||||
|
||||
r.Handle("/*", handler)
|
||||
@ -185,12 +186,21 @@ func (s *Server) createReverseProxy(ctx context.Context, target *url.URL) *httpu
|
||||
httpTransport.DialContext = dialer.DialContext
|
||||
|
||||
reverseProxy.Transport = httpTransport
|
||||
reverseProxy.ErrorHandler = s.errorHandler
|
||||
reverseProxy.ErrorHandler = s.handleError
|
||||
|
||||
return reverseProxy
|
||||
}
|
||||
|
||||
func (s *Server) errorHandler(w http.ResponseWriter, r *http.Request, err error) {
|
||||
func (s *Server) handleDefault(w http.ResponseWriter, r *http.Request) {
|
||||
err := errors.Errorf("no proxy target found")
|
||||
|
||||
logger.Error(r.Context(), "proxy error", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
|
||||
s.renderErrorPage(w, r, err, http.StatusBadGateway, http.StatusText(http.StatusBadGateway))
|
||||
}
|
||||
|
||||
func (s *Server) handleError(w http.ResponseWriter, r *http.Request, err error) {
|
||||
err = errors.WithStack(err)
|
||||
|
||||
logger.Error(r.Context(), "proxy error", logger.E(err))
|
||||
|
Reference in New Issue
Block a user