Added middleware to let excluded files skip middleware chain

This commit is contained in:
2025-02-11 19:37:39 +11:00
parent 750de24fd1
commit 97aabcf06f
6 changed files with 75 additions and 9 deletions

25
middleware/excluded.go Normal file
View File

@@ -0,0 +1,25 @@
package middleware
import (
"net/http"
"strings"
)
var excludedFiles = map[string]bool{
"/static/css/output.css": true,
}
// Checks is path requested if for an excluded file and returns the file
// instead of passing the request onto the next middleware
func ExcludedFiles(next http.Handler) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
if excludedFiles[r.URL.Path] {
filePath := strings.TrimPrefix(r.URL.Path, "/")
http.ServeFile(w, r, filePath)
} else {
next.ServeHTTP(w, r)
}
},
)
}