From c7742b341a46360d16dd9035c046f004d0fe760c Mon Sep 17 00:00:00 2001 From: SayaAndy Date: Tue, 31 Mar 2026 00:13:10 +0700 Subject: feat: enable etag middleware feat: enable compress middleware feat: trim end slash of each request url (except for root) --- internal/router/router.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'internal/router/router.go') diff --git a/internal/router/router.go b/internal/router/router.go index 1b490d8..3ce7e3b 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -21,7 +21,9 @@ import ( "github.com/SayaAndy/saya-today-web/locale" "github.com/dgraph-io/ristretto/v2" "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/compress" "github.com/gofiber/fiber/v2/middleware/cors" + "github.com/gofiber/fiber/v2/middleware/etag" "github.com/golang-migrate/migrate/v4" "github.com/golang-migrate/migrate/v4/database/sqlite3" "github.com/yuin/goldmark" @@ -226,6 +228,20 @@ func NewRouter(cfg *config.Config) (*Router, error) { AllowHeaders: "Origin, Content-Type, Accept", })) + app.Use(compress.New(compress.Config{ + Level: compress.LevelBestSpeed, + })) + + app.Use(etag.New()) + + app.Use(func(c *fiber.Ctx) error { + path := c.Path() + if len(path) > 1 && path[len(path)-1] == '/' { + return c.Redirect(strings.TrimRight(path, "/"), fiber.StatusMovedPermanently) + } + return c.Next() + }) + templatedRoutes := make(map[string]map[string]Route) templatedPathMatcher := NewPathMatcher() -- cgit v1.3.1+13