React-Frontend ausliefern, altes Vanilla-Frontend entfernt
- frontend.go: Seitenrouten liefern die index.html (no-cache), gehashte Assets unter /assets dauerhaft cachebar, sonst echtes 404 - /stats als Seite, /stats.html leitet per 301 weiter - Containerfile: Node-Stage baut das Frontend nach web/ - Vite baut nach ../web (gitignored); web/ (Vanilla-JS) gelöscht - notes/frontend.md, deploy.md angepasst Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TiXsPUqw7oeomZ8wZrQW5q
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
728ac9b45e
commit
9cac33d167
+35
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// webDir enthält das gebaute React-Frontend (frontend/ -> npm run build):
|
||||
// index.html plus gehashte Dateien unter assets/.
|
||||
const webDir = "web"
|
||||
|
||||
// serveApp liefert die index.html des Frontends; das Routing übernimmt der
|
||||
// Client. Nur für die Seitenrouten des Frontends registriert (siehe routes) --
|
||||
// beliebige andere Pfade bleiben ein echtes 404, statt als Seite zu gelten und
|
||||
// in der Impression-Statistik zu landen. no-cache, damit nach einem Deploy
|
||||
// sofort die neue index.html mit den neuen Asset-Namen geladen wird.
|
||||
func serveApp(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, webDir+"/index.html")
|
||||
}
|
||||
|
||||
// serveAssets liefert die gebauten JS/CSS-Dateien. Ihre Namen enthalten einen
|
||||
// Inhalts-Hash, sie ändern sich also nie -> dauerhaft cachebar. Verzeichnisse
|
||||
// gibt es nicht zu sehen (kein Listing).
|
||||
func serveAssets() http.Handler {
|
||||
files := http.FileServer(http.Dir(webDir))
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.HasSuffix(r.URL.Path, "/") {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
|
||||
files.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user