diff --git a/config/config.go b/config/config.go index 9549cab..8efde9e 100644 --- a/config/config.go +++ b/config/config.go @@ -50,7 +50,7 @@ func NewConfig() *Config { proxyConfig := middleware.ProxyConfig{ Skipper: middleware.DefaultSkipper, ContextKey: "target", - RetryCount: 0, + RetryCount: len(configFile.TezosHost) + 1, Balancer: balancer, RetryFilter: func(c echo.Context, err error) bool { if httpErr, ok := err.(*echo.HTTPError); ok { diff --git a/config/viper.go b/config/viper.go index e4a47ff..99e404d 100644 --- a/config/viper.go +++ b/config/viper.go @@ -10,7 +10,6 @@ import ( func initViper() *ConfigFile { - // Set the configuration file name and path viper.SetConfigName("tzproxy") viper.SetConfigType("yaml") diff --git a/main.go b/main.go index 95a0c2e..672fbda 100644 --- a/main.go +++ b/main.go @@ -12,8 +12,8 @@ import ( "github.com/fraidev/echo-contrib/echoprometheus" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" - "github.com/marigold-dev/tzproxy/middlewares" "github.com/marigold-dev/tzproxy/config" + "github.com/marigold-dev/tzproxy/middlewares" "github.com/ziflex/lecho/v3" ) diff --git a/middlewares/cache.go b/middlewares/cache.go index 5c0727b..a0eee15 100644 --- a/middlewares/cache.go +++ b/middlewares/cache.go @@ -14,7 +14,10 @@ func Cache(config *config.Config) echo.MiddlewareFunc { return echocache.New(&echocache.Config{ TTL: config.CacheTTL, Cache: func(r *http.Request) bool { - if !config.ConfigFile.Cache.Enabled || r.Method != http.MethodGet { + if !config.ConfigFile.Cache.Enabled || + r.Method != http.MethodGet || + strings.Contains(r.URL.Path, "mempool") || + strings.Contains(r.URL.Path, "monitor") { return false } diff --git a/middlewares/retry.go b/middlewares/retry.go index e770e75..f9bc9f0 100644 --- a/middlewares/retry.go +++ b/middlewares/retry.go @@ -3,6 +3,7 @@ package middlewares import ( "bytes" "net/http" + "strings" "github.com/labstack/echo/v4" "github.com/marigold-dev/tzproxy/config" @@ -11,7 +12,10 @@ import ( func Retry(config *config.Config) echo.MiddlewareFunc { return func(next echo.HandlerFunc) echo.HandlerFunc { return func(c echo.Context) (err error) { - if config.ConfigFile.TezosHostRetry == "" { + if config.ConfigFile.TezosHostRetry == "" || + c.Request().Method != http.MethodGet || + strings.Contains(c.Request().URL.Path, "mempool") || + strings.Contains(c.Request().URL.Path, "monitor") { return next(c) }