feat: update client middleware

This commit is contained in:
hanif salafi 2025-07-03 13:56:48 +07:00
parent d31abdd4d1
commit fde36e45b1
1 changed files with 8 additions and 3 deletions

View File

@ -21,14 +21,19 @@ var excludedPaths = []string{
"/health/*", "/health/*",
"/clients", "/clients",
"/clients/*", "/clients/*",
"/metrics", "*/viewer/*",
"/metrics/*",
} }
// isPathExcluded checks if the given path should be excluded from client key validation // isPathExcluded checks if the given path should be excluded from client key validation
func isPathExcluded(path string) bool { func isPathExcluded(path string) bool {
for _, excludedPath := range excludedPaths { for _, excludedPath := range excludedPaths {
if strings.HasPrefix(excludedPath, "*") { if strings.HasPrefix(excludedPath, "*") && strings.HasSuffix(excludedPath, "*") {
// Handle wildcard at both beginning and end (e.g., "*/viewer/*")
pattern := excludedPath[1 : len(excludedPath)-1] // Remove * from both ends
if strings.Contains(path, pattern) {
return true
}
} else if strings.HasPrefix(excludedPath, "*") {
// Handle wildcard at the beginning // Handle wildcard at the beginning
if strings.HasSuffix(path, excludedPath[1:]) { if strings.HasSuffix(path, excludedPath[1:]) {
return true return true