mirror of
https://github.com/wgh136/nysoure.git
synced 2025-12-16 07:51:14 +00:00
feat: add UnsupportedRegionMiddleware to handle requests from unsupported regions
This commit is contained in:
29
server/middleware/unsupported_region_middleware.go
Normal file
29
server/middleware/unsupported_region_middleware.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
func UnsupportedRegionMiddleware(c fiber.Ctx) error {
|
||||
path := string(c.Request().URI().Path())
|
||||
|
||||
// Skip static file requests
|
||||
if strings.Contains(path, ".") {
|
||||
return c.Next()
|
||||
}
|
||||
|
||||
// Skip API requests
|
||||
if strings.HasPrefix(path, "/api") {
|
||||
return c.Next()
|
||||
}
|
||||
|
||||
if string(c.Request().Header.Peek("Unsupported-Region")) == "true" {
|
||||
// Return a 403 Forbidden response with an empty html for unsupported regions
|
||||
c.Response().Header.Add("Content-Type", "text/html")
|
||||
c.Status(fiber.StatusForbidden)
|
||||
return c.SendString("<html></html>")
|
||||
}
|
||||
return c.Next()
|
||||
}
|
||||
Reference in New Issue
Block a user