// notifyprefs-api ist der Aufrufpunkt fuer CFG-06: startet den bereits // fertigen CFG-04-Handler (internal/notifyprefs) als eigenstaendigen // HTTP-Dienst, hinter derselben Session-Auth wie IAM-16 (account-api) — // GLEICHER JWT-Secret. REINES WIRING — keine Aenderung an // internal/notifyprefs/. package main import ( "context" "log" "net/http" "os" "github.com/jackc/pgx/v5/pgxpool" "gitea.perlbach24.de/scripte/nexarch/internal/auth" "gitea.perlbach24.de/scripte/nexarch/internal/notifyprefs" ) func requireEnv(name string) string { v := os.Getenv(name) if v == "" { log.Fatalf("%s muss gesetzt sein", name) } return v } func main() { dsn := requireEnv("NEXARCH_NOTIFYPREFS_TENANT_DSN") // MUSS identisch mit NEXARCH_ACCOUNT_JWT_SECRET (IAM-16) sein, sonst // verwirft dieser Dienst gueltige account-api-Sessions. jwtSecret := requireEnv("NEXARCH_NOTIFYPREFS_JWT_SECRET") addr := os.Getenv("NEXARCH_NOTIFYPREFS_API_LISTEN_ADDR") if addr == "" { addr = "127.0.0.1:8101" } ctx := context.Background() pool, err := pgxpool.New(ctx, dsn) if err != nil { log.Fatalf("datenbankverbindung: %v", err) } defer pool.Close() tokenIssuer := auth.NewTokenIssuer(jwtSecret) handler := notifyprefs.NewHandler(notifyprefs.NewStore(pool)) mux := http.NewServeMux() mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) }) mux.HandleFunc("GET /notifications/preferences", auth.RequireAuth(tokenIssuer, handler.ListMine)) mux.HandleFunc("POST /notifications/preferences", auth.RequireAuth(tokenIssuer, handler.SetPreference)) mux.HandleFunc("GET /notifications/preferences/tenant", auth.RequireAuth(tokenIssuer, handler.ListTenantOverview)) log.Printf("notifyprefs-api: listening on %s", addr) if err := http.ListenAndServe(addr, mux); err != nil { log.Fatalf("http server: %v", err) } }