fix: add correct content-type to their respective files
This commit is contained in:
22
main.go
22
main.go
@@ -34,21 +34,23 @@ func SafeFileServer(root http.FileSystem) http.Handler {
|
|||||||
w.Header().Set("X-XSS-Protection", "1; mode=block")
|
w.Header().Set("X-XSS-Protection", "1; mode=block")
|
||||||
|
|
||||||
log.Println("assets handler", r.URL.Path)
|
log.Println("assets handler", r.URL.Path)
|
||||||
|
log.Println(w.Header())
|
||||||
|
|
||||||
// Only allow specific file extensions
|
// Only allow specific file extensions
|
||||||
if allowed := func(path string) bool {
|
if allowed := func(path string) bool {
|
||||||
allowedExts := map[string]bool{
|
allowedExts := map[string]string{
|
||||||
".js": true,
|
".js": "text/javascript;charset=utf-8",
|
||||||
".css": true,
|
".css": "text/css;charset=utf-8",
|
||||||
".png": true,
|
".png": "image/png",
|
||||||
".webp": true,
|
".webp": "image/webp",
|
||||||
".jpg": true,
|
".jpg": "image/jpeg",
|
||||||
".jpeg": true,
|
".jpeg": "image/jpeg",
|
||||||
".svg": true,
|
".svg": "image/svg+xml",
|
||||||
".ico": true,
|
".ico": "image/x-icon",
|
||||||
}
|
}
|
||||||
for ext := range allowedExts {
|
for ext, contentType := range allowedExts {
|
||||||
if strings.HasSuffix(path, ext) {
|
if strings.HasSuffix(path, ext) {
|
||||||
|
w.Header().Set("Content-Type", contentType)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user