Skip to content

Commit 8c2fb25

Browse files
committed
Proper fix for redirects -- Wavelog does not like redirects
1 parent 692956f commit 8c2fb25

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

main.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,22 @@ func initializeDXClusters(ctx context.Context, cfg *config.Config) ([]*cluster.C
337337
func setupHTTPRouter(cfg *config.Config) *gin.Engine {
338338
gin.SetMode(gin.ReleaseMode)
339339
router := gin.New()
340-
router.RedirectTrailingSlash = true
341-
router.RedirectFixedPath = true
340+
341+
// Normalize paths: remove trailing slashes and collapse multiple slashes
342+
router.Use(func(c *gin.Context) {
343+
path := c.Request.URL.Path
344+
// Collapse multiple slashes
345+
for strings.Contains(path, "//") {
346+
path = strings.ReplaceAll(path, "//", "/")
347+
}
348+
// Remove trailing slash (except for root)
349+
if len(path) > 1 && strings.HasSuffix(path, "/") {
350+
path = strings.TrimSuffix(path, "/")
351+
}
352+
c.Request.URL.Path = path
353+
c.Next()
354+
})
355+
342356
router.Use(logging.GinRecovery())
343357
router.Use(logging.GinLogger())
344358

0 commit comments

Comments
 (0)