39 lines · 849 B · Go
RawDownload
package middleware import (	"strings" 	"github.com/gofiber/fiber/v2"	"github.com/mauriciogm/dokploy/apps/monitoring/config") func AuthMiddleware() fiber.Handler {	return func(c *fiber.Ctx) error {		expectedToken := config.GetMetricsConfig().Server.Token 		authHeader := c.Get("Authorization")		if authHeader == "" {			return c.Status(401).JSON(fiber.Map{				"error": "Authorization header is required",			})		} 		// Check if the header starts with "Bearer "		if !strings.HasPrefix(authHeader, "Bearer ") {			return c.Status(401).JSON(fiber.Map{				"error": "Invalid authorization format. Use 'Bearer TOKEN'",			})		} 		// Extract the token		token := strings.TrimPrefix(authHeader, "Bearer ") 		if token != expectedToken {			return c.Status(401).JSON(fiber.Map{				"error": "Invalid token",			})		} 		return c.Next()	}}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t