updated godoc and renamed cors middleware handler

This commit is contained in:
Gani Georgiev
2024-11-21 22:22:58 +02:00
parent 31d3c27f43
commit 5d8a8dd7d8
3 changed files with 6 additions and 4 deletions

View File

@@ -124,8 +124,8 @@ var DefaultCORSConfig = CORSConfig{
AllowMethods: []string{http.MethodGet, http.MethodHead, http.MethodPut, http.MethodPatch, http.MethodPost, http.MethodDelete},
}
// CORSWithConfig returns a CORS middleware with config.
func CORSWithConfig(config CORSConfig) *hook.Handler[*core.RequestEvent] {
// CORS returns a CORS middleware.
func CORS(config CORSConfig) *hook.Handler[*core.RequestEvent] {
// Defaults
if len(config.AllowOrigins) == 0 {
config.AllowOrigins = DefaultCORSConfig.AllowOrigins
@@ -272,6 +272,7 @@ func matchSubdomain(domain, pattern string) bool {
if !matchScheme(domain, pattern) {
return false
}
didx := strings.Index(domain, "://")
pidx := strings.Index(pattern, "://")
if didx == -1 || pidx == -1 {
@@ -307,5 +308,6 @@ func matchSubdomain(domain, pattern string) bool {
return false
}
}
return false
}