summaryrefslogtreecommitdiff
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
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)
-rw-r--r--internal/router/handlers/root.go4
-rw-r--r--internal/router/router.go16
2 files changed, 18 insertions, 2 deletions
diff --git a/internal/router/handlers/root.go b/internal/router/handlers/root.go
index f188a61..cd01fcd 100644
--- a/internal/router/handlers/root.go
+++ b/internal/router/handlers/root.go
@@ -37,14 +37,14 @@ func (r *RootHandler) CacheDuration() time.Duration {
}
func (r *RootHandler) SitemapInfo(_ *router.Supplements) []router.SitemapInfo {
- return []router.SitemapInfo{{Loc: "", Priority: 0.7}}
+ return []router.SitemapInfo{{Loc: "/", Priority: 0.7}}
}
func (r *RootHandler) AddMeta(c *fiber.Ctx, supplements *router.Supplements, lang string, templateMap fiber.Map) (meta []router.MetaField, err error) {
return []router.MetaField{
{Property: "og:title", Content: "Saya Blog"},
{Property: "og:description", Content: "The blog of a 25 years old, travelling God knows where, proud to be not mainstream // Личный блог 25-летки, странствующего по ебеням, зато не мейнстрим"},
- {Property: "og:url", Content: fmt.Sprint(templateMap["CanonicalEndpoint"])},
+ {Property: "og:url", Content: fmt.Sprint(templateMap["CanonicalEndpoint"]) + "/"},
{Property: "og:type", Content: "website"},
}, nil
}
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()