feat: pwa auto-update; fix WS hijack, DM names, tap reactions
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user