fix: add correct content-type to their respective files

This commit is contained in:
2025-02-21 19:06:28 +01:00
parent d17932adb6
commit 4879729893

22
main.go
View File

@@ -34,21 +34,23 @@ func SafeFileServer(root http.FileSystem) http.Handler {
w.Header().Set("X-XSS-Protection", "1; mode=block")
log.Println("assets handler", r.URL.Path)
log.Println(w.Header())
// Only allow specific file extensions
if allowed := func(path string) bool {
allowedExts := map[string]bool{
".js": true,
".css": true,
".png": true,
".webp": true,
".jpg": true,
".jpeg": true,
".svg": true,
".ico": true,
allowedExts := map[string]string{
".js": "text/javascript;charset=utf-8",
".css": "text/css;charset=utf-8",
".png": "image/png",
".webp": "image/webp",
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".svg": "image/svg+xml",
".ico": "image/x-icon",
}
for ext := range allowedExts {
for ext, contentType := range allowedExts {
if strings.HasSuffix(path, ext) {
w.Header().Set("Content-Type", contentType)
return true
}
}