fix(web): манифест PWA отдаётся с правильным типом

Go определяет .webmanifest как text/plain, из-за чего браузер мог отказаться
ставить приложение: тип задаём явно вместе с js/css/svg.
This commit is contained in:
2026-09-21 19:45:25 +03:00
parent 5afcfee744
commit dd4432452c
6 changed files with 217 additions and 1 deletions
+18 -1
View File
@@ -39,7 +39,9 @@ func (h *staticHandler) serve(w http.ResponseWriter, r *http.Request) {
return
}
if contentType := mime.TypeByExtension(filepath.Ext(rel)); contentType != "" {
// Часть расширений (манифест PWA) известна не всем системам: тип задаём
// явно, иначе браузер получает text/plain и отказывается ставить приложение.
if contentType := staticContentType(rel); contentType != "" {
w.Header().Set("Content-Type", contentType)
}
if strings.HasPrefix(rel, "assets/") {
@@ -50,6 +52,21 @@ func (h *staticHandler) serve(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, filepath.Join(h.root, filepath.FromSlash(rel)))
}
// staticContentType определяет тип файла: сначала явные правила, потом mime.
func staticContentType(rel string) string {
switch filepath.Ext(rel) {
case ".webmanifest":
return "application/manifest+json"
case ".js":
return "text/javascript; charset=utf-8"
case ".css":
return "text/css; charset=utf-8"
case ".svg":
return "image/svg+xml"
}
return mime.TypeByExtension(filepath.Ext(rel))
}
func (h *staticHandler) serveIndex(w http.ResponseWriter, r *http.Request) {
index := filepath.Join(h.root, "index.html")
if _, err := os.Stat(index); err != nil {