Fixed static file embedding

This commit is contained in:
2025-02-16 17:57:27 +11:00
parent f9e17211ce
commit fafb9b436f
7 changed files with 34 additions and 53 deletions

View File

@@ -1,25 +0,0 @@
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)
}
},
)
}

View File

@@ -1,17 +0,0 @@
package middleware
import (
"net/http"
)
func Favicon(next http.Handler) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/favicon.ico" {
http.ServeFile(w, r, "static/favicon.ico")
} else {
next.ServeHTTP(w, r)
}
},
)
}