summaryrefslogtreecommitdiffci
path: root/internal/router/router.go
diff options
from:
to:
context:
space:
mode:
authorGravatar SayaAndy <saya.andy@posteo.com> 2026-03-31 00:13:10 +0700
committerGravatar SayaAndy <saya.andy@posteo.com> 2026-03-31 00:13:10 +0700
commitc7742b341a46360d16dd9035c046f004d0fe760c (patch)
treefa453143f80c357755955e870b7c8f47f47abb49 /internal/router/router.go
parenta0ace41ad3b0f4661e98d8fa8ef254369cc80d1e (diff)
downloadweb-c7742b341a46360d16dd9035c046f004d0fe760c.tar.gz
web-c7742b341a46360d16dd9035c046f004d0fe760c.zip
feat: enable etag middleware
feat: enable compress middleware feat: trim end slash of each request url (except for root)
Diffstat (limited to 'internal/router/router.go')
-rw-r--r--internal/router/router.go16
1 files changed, 16 insertions, 0 deletions
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()