fix(web): mw.CORS rejects wildcard; fix README fences; align to v1.1.2

This commit is contained in:
2026-08-08 00:43:09 -06:00
parent c6a753e49b
commit 8876af3bfa
5 changed files with 38 additions and 13 deletions
+9
View File
@@ -11,6 +11,15 @@ const (
// Returns 204 No Content for OPTIONS preflight requests.
// Pass the outermost origins first; an empty slice is a no-op.
func CORS(origins []string) func(http.Handler) http.Handler {
// "*" is a silent no-op here (exact-match only) — reject it loudly at
// construction so a misconfigured service fails to boot instead of quietly
// blocking every browser. For allow-all, call CORSAllowAll (development only).
for _, o := range origins {
if o == "*" {
panic(`mw.CORS: "*" is not a valid origin — list explicit origins, or use CORSAllowAll() for allow-all`)
}
}
originSet := make(map[string]struct{}, len(origins))
for _, o := range origins {
originSet[o] = struct{}{}