feat: pwa auto-update; fix WS hijack, DM names, tap reactions
CI / Go (build + vet + test) (push) Canceled after 0s
CI / Web (build + lint) (push) Canceled after 0s

This commit is contained in:
vantablackTea
2026-09-28 14:18:44 +03:00
parent a0b17d25bf
commit 82fa4b029f
3 changed files with 52 additions and 3 deletions
+14
View File
@@ -6,6 +6,7 @@ import (
"encoding/json"
"log/slog"
"net/http"
"strings"
"time"
"messenger/internal/api"
@@ -72,13 +73,26 @@ func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
defer index.Close()
w.Header().Set("Cache-Control", "no-cache")
http.ServeContent(w, r, "index.html", time.Time{}, index)
return
}
defer f.Close()
setStaticCache(w, path)
http.ServeContent(w, r, path, time.Time{}, f)
}
// setStaticCache lets hashed assets be cached forever while forcing the app
// shell, service worker and manifest to revalidate on every load.
func setStaticCache(w http.ResponseWriter, path string) {
switch {
case strings.HasPrefix(path, "/assets/"):
w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
case path == "/index.html" || path == "/sw.js" || path == "/manifest.webmanifest":
w.Header().Set("Cache-Control", "no-cache")
}
}
func writeJSON(w http.ResponseWriter, status int, body any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)