40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func withCORS(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
origin := strings.TrimSpace(r.Header.Get("Origin"))
|
|
|
|
// Dev-Origins erlauben
|
|
if origin == "http://localhost:5173" ||
|
|
origin == "http://127.0.0.1:5173" ||
|
|
origin == "http://10.0.1.25:5173" ||
|
|
origin == "https://localhost:5173" ||
|
|
origin == "https://127.0.0.1:5173" ||
|
|
origin == "https://10.0.1.25:5173" {
|
|
w.Header().Set("Access-Control-Allow-Origin", origin)
|
|
w.Header().Set("Vary", "Origin")
|
|
w.Header().Set("Access-Control-Allow-Methods", "GET,POST,DELETE,HEAD,OPTIONS")
|
|
w.Header().Set(
|
|
"Access-Control-Allow-Headers",
|
|
"Content-Type, Range, Last-Event-ID, X-Chaturbate-Cookie, Authorization",
|
|
)
|
|
w.Header().Set("Access-Control-Expose-Headers", "Content-Length, Content-Range, Accept-Ranges")
|
|
w.Header().Set("Access-Control-Allow-Credentials", "true")
|
|
// Nur wenn du wirklich Cookies/Authorization cross-origin brauchst:
|
|
// w.Header().Set("Access-Control-Allow-Credentials", "true")
|
|
}
|
|
|
|
if r.Method == http.MethodOptions {
|
|
w.WriteHeader(http.StatusNoContent)
|
|
return
|
|
}
|
|
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|