Rechtstexte als App-Seiten statt statischer HTML-Seiten
Impressum, Datenschutz und Beitragsordnung liegen als HTML-Fragmente in frontend/src/docs und werden unter /impressum, /datenschutz und /beitragsordnung in der App mit der einheitlichen Navigation gezeigt. Die alten Adressen /static/docs/*.html leiten per 301 dorthin um. 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
15b0bfc69c
commit
f0dbb67054
@@ -2,10 +2,7 @@ package httpapi
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
// webDir enthält das gebaute React-Frontend (frontend/ -> npm run build):
|
||||
@@ -22,13 +19,6 @@ func serveApp(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, webDir+"/index.html")
|
||||
}
|
||||
|
||||
// serveDoc liefert einen Rechtstext. Sie werden mit dem Frontend gebaut
|
||||
// (frontend/static/docs), damit sie dasselbe app.css bekommen.
|
||||
func serveDoc(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, webDir+"/static/docs/"+path.Base(chi.URLParam(r, "page")))
|
||||
}
|
||||
|
||||
// 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).
|
||||
|
||||
@@ -129,8 +129,12 @@ func (s *Server) pageRoutes(r chi.Router) {
|
||||
// Das Reset-Token steht im Fragment (#...) und erreicht den Server über
|
||||
// diese Route nie, siehe account/reset.go.
|
||||
r.Get("/reset", serveApp)
|
||||
// Navigationsziele: Profil-Weiche und Platzhalter für kommende Bereiche.
|
||||
for _, p := range []string{"/me", "/search", "/notifications", "/chats", "/settings"} {
|
||||
// Navigationsziele: Profil-Weiche, Platzhalter für kommende Bereiche und
|
||||
// die Rechtstexte.
|
||||
for _, p := range []string{
|
||||
"/me", "/search", "/notifications", "/chats", "/settings",
|
||||
"/impressum", "/datenschutz", "/beitragsordnung",
|
||||
} {
|
||||
r.Get(p, serveApp)
|
||||
}
|
||||
// Alte Adresse der Statistik-Seite (Lesezeichen, Links von außen).
|
||||
@@ -138,7 +142,12 @@ func (s *Server) pageRoutes(r chi.Router) {
|
||||
http.Redirect(w, r, "/stats", http.StatusMovedPermanently)
|
||||
})
|
||||
r.Handle("/assets/*", serveAssets())
|
||||
r.Get("/static/docs/{page}", serveDoc)
|
||||
// Alte Adressen der Rechtstexte (bis 2026-10 statische Seiten).
|
||||
for _, name := range []string{"impressum", "datenschutz", "beitragsordnung"} {
|
||||
r.Get("/static/docs/"+name+".html", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "/"+name, http.StatusMovedPermanently)
|
||||
})
|
||||
}
|
||||
|
||||
// Hochgeladene Medien + statische Dateien (Schriften, Bilder).
|
||||
// nosniff (global via secHeaders) verhindert, dass der Browser eine
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/netip"
|
||||
"testing"
|
||||
@@ -58,3 +59,32 @@ func (srv *testServer) resetToken(t *testing.T, username string) string {
|
||||
}
|
||||
return token
|
||||
}
|
||||
|
||||
// TestOldDocURLs: die früheren statischen Rechtstexte leiten auf die
|
||||
// App-Seiten um, andere Pfade darunter gibt es nicht mehr.
|
||||
func TestOldDocURLs(t *testing.T) {
|
||||
t.Parallel()
|
||||
srv := newTestServer(t)
|
||||
c := &http.Client{CheckRedirect: func(*http.Request, []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
}}
|
||||
for _, tc := range []struct {
|
||||
path, wantLoc string
|
||||
wantStatus int
|
||||
}{
|
||||
{"/static/docs/impressum.html", "/impressum", http.StatusMovedPermanently},
|
||||
{"/static/docs/datenschutz.html", "/datenschutz", http.StatusMovedPermanently},
|
||||
{"/static/docs/beitragsordnung.html", "/beitragsordnung", http.StatusMovedPermanently},
|
||||
{"/static/docs/geheim.html", "", http.StatusNotFound},
|
||||
} {
|
||||
resp, err := c.Get(srv.URL + tc.path)
|
||||
if err != nil {
|
||||
t.Fatalf("GET %s: %v", tc.path, err)
|
||||
}
|
||||
_ = resp.Body.Close()
|
||||
if resp.StatusCode != tc.wantStatus || resp.Header.Get("Location") != tc.wantLoc {
|
||||
t.Errorf("GET %s: %d %q, erwartet %d %q", tc.path,
|
||||
resp.StatusCode, resp.Header.Get("Location"), tc.wantStatus, tc.wantLoc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user