feat: add frontend prototype

This commit is contained in:
Philipp
2026-06-10 20:14:46 +02:00
parent 772ed6bf8d
commit b08b52dd1b
10 changed files with 760 additions and 26 deletions
+20 -1
View File
@@ -62,7 +62,7 @@ func main() {
server := &http.Server{
Addr: cfg.BackendAddr,
Handler: mux,
Handler: withCORS(cfg.AppSiteURL, mux),
ReadHeaderTimeout: 5 * time.Second,
}
@@ -103,3 +103,22 @@ func openDatabase(databaseURL string) (*sql.DB, error) {
return db, nil
}
func withCORS(allowedOrigin string, next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
origin := r.Header.Get("Origin")
if origin != "" && origin == allowedOrigin {
w.Header().Set("Access-Control-Allow-Origin", allowedOrigin)
w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS")
w.Header().Set("Vary", "Origin")
}
if r.Method == http.MethodOptions {
w.WriteHeader(http.StatusNoContent)
return
}
next.ServeHTTP(w, r)
})
}