fix: stupid issues in browser

This commit is contained in:
2026-04-21 08:24:35 +02:00
parent ee3c22db9d
commit 0b2957d68c

View File

@@ -3,6 +3,8 @@ package server
import (
"database/sql"
"net/http"
"path/filepath"
"strings"
"mal/api/anime"
"mal/api/auth"
@@ -22,6 +24,23 @@ type Config struct {
PlaybackProxySecret string
}
func withMimeTypes(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ext := strings.ToLower(filepath.Ext(r.URL.Path))
switch ext {
case ".js":
w.Header().Set("Content-Type", "application/javascript")
case ".css":
w.Header().Set("Content-Type", "text/css")
case ".svg":
w.Header().Set("Content-Type", "image/svg+xml")
case ".json":
w.Header().Set("Content-Type", "application/json")
}
next.ServeHTTP(w, r)
})
}
func NewRouter(cfg Config) http.Handler {
mux := http.NewServeMux()
@@ -40,7 +59,7 @@ func NewRouter(cfg Config) http.Handler {
// Serve built frontend assets
dist := http.FileServer(http.Dir("./dist"))
mux.Handle("/dist/", http.StripPrefix("/dist/", dist))
mux.Handle("/dist/", http.StripPrefix("/dist/", withMimeTypes(dist)))
mux.HandleFunc("/", animeHandler.HandleCatalog)
mux.HandleFunc("/discover", animeHandler.HandleDiscover)