commit cd69f9955cec4aa685569989a699001f12a629f3
parent 27d57e0c73c1c02daed555b192d27a952a7be17d
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Thu, 22 Jun 2023 00:15:50 -0700
cleanup
Diffstat:
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/pkg/web/web.go b/pkg/web/web.go
@@ -355,16 +355,7 @@ func getTorServer(db *database.DkfDB) *echo.Echo {
host := c.Request().Host
hostParts := strings.SplitN(host, ".", 2)
if hostParts[0] == "git" {
- remote, _ := url.Parse(config.GogsURL)
- reverseProxy := httputil.NewSingleHostReverseProxy(remote)
- reverseProxy.FlushInterval = 1000 * time.Millisecond
- reverseProxy.ErrorHandler = func(w http.ResponseWriter, req *http.Request, e error) {
- if e.Error() != "context canceled" {
- logrus.Error(e.Error())
- }
- w.WriteHeader(http.StatusBadGateway)
- }
- reverseProxy.ServeHTTP(c.Response(), c.Request())
+ getReverseProxy(config.GogsURL).ServeHTTP(c.Response(), c.Request())
return nil
}
getBaseServer(db).ServeHTTP(c.Response(), c.Request())
@@ -451,6 +442,22 @@ func extractGlobalCircuitIdentifier(m string) int64 {
return globalCircuitID
}
+func getReverseProxy(u string) http.Handler {
+ remote, err := url.Parse(u)
+ if err != nil {
+ panic(err)
+ }
+ reverseProxy := httputil.NewSingleHostReverseProxy(remote)
+ reverseProxy.FlushInterval = 1000 * time.Millisecond
+ reverseProxy.ErrorHandler = func(w http.ResponseWriter, req *http.Request, e error) {
+ if e.Error() != "context canceled" {
+ logrus.Error(e.Error())
+ }
+ w.WriteHeader(http.StatusBadGateway)
+ }
+ return reverseProxy
+}
+
func configTorProdServer(e *echo.Echo) {
if config.Development.IsTrue() {
return