summaryrefslogtreecommitdiff
path: root/internal/router/router.go
diff options
from:
to:
context:
space:
mode:
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()