fix: stupid issues in browser
This commit is contained in:
@@ -3,6 +3,8 @@ package server
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"mal/api/anime"
|
"mal/api/anime"
|
||||||
"mal/api/auth"
|
"mal/api/auth"
|
||||||
@@ -22,6 +24,23 @@ type Config struct {
|
|||||||
PlaybackProxySecret string
|
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 {
|
func NewRouter(cfg Config) http.Handler {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
@@ -40,7 +59,7 @@ func NewRouter(cfg Config) http.Handler {
|
|||||||
|
|
||||||
// Serve built frontend assets
|
// Serve built frontend assets
|
||||||
dist := http.FileServer(http.Dir("./dist"))
|
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("/", animeHandler.HandleCatalog)
|
||||||
mux.HandleFunc("/discover", animeHandler.HandleDiscover)
|
mux.HandleFunc("/discover", animeHandler.HandleDiscover)
|
||||||
|
|||||||
Reference in New Issue
Block a user