summaryrefslogtreecommitdiff
path: root/internal/router
diff refs
from: back
to: back
| flip
diff options
context:
space:
mode:
Diffstat (limited to 'internal/router')
-rw-r--r--internal/router/basic-handler.go4
-rw-r--r--internal/router/handlers/api-v1-blog-search.go4
-rw-r--r--internal/router/handlers/api-v1-email-send-verification-code.go4
-rw-r--r--internal/router/handlers/api-v1-email-verify.go4
-rw-r--r--internal/router/handlers/api-v1-like-put.go4
-rw-r--r--internal/router/handlers/api-v1-subs-put.go4
-rw-r--r--internal/router/handlers/root.go3
-rw-r--r--internal/router/rate-limiters.go37
-rw-r--r--internal/router/router.go41
9 files changed, 4 insertions, 101 deletions
diff --git a/internal/router/basic-handler.go b/internal/router/basic-handler.go
index 68d305c..b973d01 100644
--- a/internal/router/basic-handler.go
+++ b/internal/router/basic-handler.go
@@ -42,10 +42,6 @@ func (r *BasicHandler) ContentType() string {
return fiber.MIMETextHTMLCharsetUTF8
}
-func (r *BasicHandler) RateLimiter() *fiber.Handler {
- return nil
-}
-
func (r *BasicHandler) Render(c *fiber.Ctx, supplements *Supplements, lang string, templateMap fiber.Map) (statusCode int, err error) {
if !r.IsTemplated() {
panic("handler did not implement Render method (while being non-templated)")
diff --git a/internal/router/handlers/api-v1-blog-search.go b/internal/router/handlers/api-v1-blog-search.go
index 38004a1..c9a91ad 100644
--- a/internal/router/handlers/api-v1-blog-search.go
+++ b/internal/router/handlers/api-v1-blog-search.go
@@ -44,10 +44,6 @@ func (r *BlogSearchHandler) ToValidateLang() router.LangSetting {
return router.InForm
}
-func (r *BlogSearchHandler) RateLimiter() *fiber.Handler {
- return &router.RateLimiterLoose
-}
-
func (r *BlogSearchHandler) Render(c *fiber.Ctx, supplements *router.Supplements, lang string, templateMap fiber.Map) (statusCode int, err error) {
sort := c.Query("sort")
tz := c.Query("tz")
diff --git a/internal/router/handlers/api-v1-email-send-verification-code.go b/internal/router/handlers/api-v1-email-send-verification-code.go
index 0b53efa..20c5fb6 100644
--- a/internal/router/handlers/api-v1-email-send-verification-code.go
+++ b/internal/router/handlers/api-v1-email-send-verification-code.go
@@ -38,10 +38,6 @@ func (r *SendVerificationCodeHandler) ToValidateLang() router.LangSetting {
return router.InReferer
}
-func (r *SendVerificationCodeHandler) RateLimiter() *fiber.Handler {
- return &router.RateLimiterStrict
-}
-
func (r *SendVerificationCodeHandler) Render(c *fiber.Ctx, supplements *router.Supplements, lang string, templateMap fiber.Map) (statusCode int, err error) {
id := c.IP()
templateMap["StatusId"] = "email-message"
diff --git a/internal/router/handlers/api-v1-email-verify.go b/internal/router/handlers/api-v1-email-verify.go
index ace1870..c9ec969 100644
--- a/internal/router/handlers/api-v1-email-verify.go
+++ b/internal/router/handlers/api-v1-email-verify.go
@@ -36,10 +36,6 @@ func (r *VerifyCodeHandler) ToValidateLang() router.LangSetting {
return router.InReferer
}
-func (r *VerifyCodeHandler) RateLimiter() *fiber.Handler {
- return &router.RateLimiterStrict
-}
-
func (r *VerifyCodeHandler) Render(c *fiber.Ctx, supplements *router.Supplements, lang string, templateMap fiber.Map) (statusCode int, err error) {
verificationCode := c.FormValue("email_code")
templateMap["StatusId"] = "verification-message"
diff --git a/internal/router/handlers/api-v1-like-put.go b/internal/router/handlers/api-v1-like-put.go
index 8305d2b..434f15a 100644
--- a/internal/router/handlers/api-v1-like-put.go
+++ b/internal/router/handlers/api-v1-like-put.go
@@ -37,10 +37,6 @@ func (r *PutLikeHandler) ToValidateLang() router.LangSetting {
return router.InReferer
}
-func (r *PutLikeHandler) RateLimiter() *fiber.Handler {
- return &router.RateLimiterMedium
-}
-
func (r *PutLikeHandler) Render(c *fiber.Ctx, supplements *router.Supplements, lang string, templateMap fiber.Map) (statusCode int, err error) {
path, pathParts, _, err := router.GetPathFromReferer(c)
if err != nil {
diff --git a/internal/router/handlers/api-v1-subs-put.go b/internal/router/handlers/api-v1-subs-put.go
index 32fba7e..144abe5 100644
--- a/internal/router/handlers/api-v1-subs-put.go
+++ b/internal/router/handlers/api-v1-subs-put.go
@@ -34,10 +34,6 @@ func (r *PutSubsHandler) ToValidateLang() router.LangSetting {
return router.InReferer
}
-func (r *PutSubsHandler) RateLimiter() *fiber.Handler {
- return &router.RateLimiterMedium
-}
-
func (r *PutSubsHandler) Render(c *fiber.Ctx, supplements *router.Supplements, lang string, templateMap fiber.Map) (statusCode int, err error) {
templateMap["StatusId"] = "subs-message"
diff --git a/internal/router/handlers/root.go b/internal/router/handlers/root.go
index 6a011e4..a8890fa 100644
--- a/internal/router/handlers/root.go
+++ b/internal/router/handlers/root.go
@@ -50,9 +50,6 @@ func (r *RootHandler) AddMeta(c *fiber.Ctx, supplements *router.Supplements, lan
if supplements.Meta.GoogleSiteVerification != "" {
meta = append(meta, router.MetaField{Name: "google-site-verification", Content: supplements.Meta.GoogleSiteVerification})
}
- if supplements.Meta.YandexVerification != "" {
- meta = append(meta, router.MetaField{Name: "yandex-verification", Content: supplements.Meta.YandexVerification})
- }
return meta, nil
}
diff --git a/internal/router/rate-limiters.go b/internal/router/rate-limiters.go
deleted file mode 100644
index b43581d..0000000
--- a/internal/router/rate-limiters.go
+++ /dev/null
@@ -1,37 +0,0 @@
-package router
-
-import (
- "time"
-
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/fiber/v2/middleware/limiter"
-)
-
-var (
- RateLimiterStrict = limiter.New(limiter.Config{
- Max: 5,
- Expiration: time.Minute,
- KeyGenerator: func(c *fiber.Ctx) string { return c.IP() },
- LimitReached: func(c *fiber.Ctx) error {
- return c.Status(fiber.StatusTooManyRequests).SendString("rate limit")
- },
- })
-
- RateLimiterMedium = limiter.New(limiter.Config{
- Max: 30,
- Expiration: time.Minute,
- KeyGenerator: func(c *fiber.Ctx) string { return c.IP() },
- LimitReached: func(c *fiber.Ctx) error {
- return c.Status(fiber.StatusTooManyRequests).SendString("rate limit")
- },
- })
-
- RateLimiterLoose = limiter.New(limiter.Config{
- Max: 60,
- Expiration: time.Minute,
- KeyGenerator: func(c *fiber.Ctx) string { return c.IP() },
- LimitReached: func(c *fiber.Ctx) error {
- return c.Status(fiber.StatusTooManyRequests).SendString("rate limit")
- },
- })
-)
diff --git a/internal/router/router.go b/internal/router/router.go
index 65e35a4..926d21a 100644
--- a/internal/router/router.go
+++ b/internal/router/router.go
@@ -7,11 +7,8 @@ import (
"fmt"
"html/template"
"log/slog"
- "net"
"net/url"
- "os"
"slices"
- "strconv"
"strings"
"time"
@@ -81,7 +78,6 @@ type Route interface {
TemplatesToInject() []string
SitemapInfo(supplements *Supplements) []SitemapInfo
ContentType() string
- RateLimiter() *fiber.Handler
Render(c *fiber.Ctx, supplements *Supplements, lang string, templateMap fiber.Map) (statusCode int, err error)
AddMeta(c *fiber.Ctx, supplements *Supplements, lang string, templateMap fiber.Map) (meta []MetaField, err error)
AddLinkedData(c *fiber.Ctx, supplements *Supplements, lang string, templateMap fiber.Map) (ld map[string]any, err error)
@@ -115,7 +111,6 @@ type Router struct {
templatedRoutes map[string]map[string]Route
templatedPathMatcher *PathMatcher
canonicalEndpoint string
- endpoint config.EndpointConfig
}
func NewRouter(cfg *config.Config) (*Router, error) {
@@ -260,7 +255,7 @@ func NewRouter(cfg *config.Config) (*Router, error) {
templatedRoutes := make(map[string]map[string]Route)
templatedPathMatcher := NewPathMatcher()
- return &Router{supplements, app, templatedRoutes, templatedPathMatcher, cfg.CanonicalEndpoint, cfg.Endpoint}, nil
+ return &Router{supplements, app, templatedRoutes, templatedPathMatcher, cfg.CanonicalEndpoint}, nil
}
func (r *Router) InitRoutes() (err error) {
@@ -272,10 +267,6 @@ func (r *Router) InitRoutes() (err error) {
return fmt.Errorf("failed to add '%s %s' route into template manager: %w", method, match, err)
}
- if rateLimiter := route.RateLimiter(); rateLimiter != nil {
- r.app.Use(match, *rateLimiter)
- }
-
if route.IsTemplated() {
if _, ok := r.templatedRoutes[method]; !ok {
r.templatedRoutes[method] = make(map[string]Route)
@@ -309,8 +300,6 @@ func (r *Router) InitRoutes() (err error) {
cacheKey = fmt.Sprintf("%s.full-page.%s", method, trimmedPath)
case ByUrlAndQuery:
cacheKey = fmt.Sprintf("%s.full-page.%s.%s", method, trimmedPath, queryString)
- case Disabled:
- c.Set("Cache-Control", "no-store, no-cache, must-revalidate")
}
defaultMap := fiber.Map{
@@ -373,7 +362,6 @@ func (r *Router) InitRoutes() (err error) {
c.Set(fiber.HeaderContentType, fiber.MIMETextPlainCharsetUTF8)
return c.Status(fiber.ErrBadRequest.Code).SendString(fmt.Sprintf("unknown segment '%s'", part))
}
- c.Set("Cache-Control", "no-store, no-cache, must-revalidate")
err := r.generalPageSegment(c, part)
return err
})
@@ -389,30 +377,10 @@ func (r *Router) InitRoutes() (err error) {
return nil
}
-func (r *Router) Listen() error {
- switch r.endpoint.Type {
- case "unix":
- unixConfig := r.endpoint.Config.(*config.UnixConfig)
- endpoint, _ := strings.CutPrefix(unixConfig.Path, "unix://")
- ln, err := net.Listen("unix", endpoint)
- if err != nil {
- return fmt.Errorf("error while initializing unix listener: %w", err)
- }
- chmod, _ := strconv.ParseUint(unixConfig.Chmod[1:], 8, 32)
- os.Chmod(unixConfig.Path, os.FileMode(chmod))
- if err := r.app.Listener(ln); err != nil {
- return fmt.Errorf("error while running fiber server: %w", err)
- }
- case "http":
- httpConfig := r.endpoint.Config.(*config.HttpConfig)
- fmt.Print(httpConfig)
- if err := r.app.Listen(httpConfig.ListenOn); err != nil {
- return fmt.Errorf("error while running fiber server: %w", err)
- }
- default:
- return fmt.Errorf("error with initializing fiber server: invalid endpoint type (supported are unix and http)")
+func (r *Router) Listen(endpoint string) error {
+ if err := r.app.Listen(endpoint); err != nil {
+ return fmt.Errorf("error while running fiber server: %w", err)
}
-
return nil
}
@@ -436,7 +404,6 @@ func (r *Router) Close() (err error) {
}
slog.Debug("closing page cache")
r.supplements.PageCache.Close()
-
return errors.Join(allErrors...)
}