From 5d8a8dd7d8292b7f52fc70cae777e12b630b0f3f Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Thu, 21 Nov 2024 22:22:58 +0200 Subject: [PATCH] updated godoc and renamed cors middleware handler --- apis/middlewares_body_limit.go | 2 +- apis/middlewares_cors.go | 6 ++++-- apis/serve.go | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apis/middlewares_body_limit.go b/apis/middlewares_body_limit.go index aac09a06..3661a2e4 100644 --- a/apis/middlewares_body_limit.go +++ b/apis/middlewares_body_limit.go @@ -18,7 +18,7 @@ const ( DefaultBodyLimitMiddlewarePriority = DefaultRateLimitMiddlewarePriority + 10 ) -// BodyLimit returns a middleware function that changes the default request body size limit. +// BodyLimit returns a middleware handler that changes the default request body size limit. // // If limitBytes <= 0, no limit is applied. // diff --git a/apis/middlewares_cors.go b/apis/middlewares_cors.go index 1c4e2c6d..ef9ff8e2 100644 --- a/apis/middlewares_cors.go +++ b/apis/middlewares_cors.go @@ -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 } diff --git a/apis/serve.go b/apis/serve.go index 7b23fe5b..41b27f56 100644 --- a/apis/serve.go +++ b/apis/serve.go @@ -72,7 +72,7 @@ func Serve(app core.App, config ServeConfig) error { return err } - pbRouter.Bind(CORSWithConfig(CORSConfig{ + pbRouter.Bind(CORS(CORSConfig{ AllowOrigins: config.AllowedOrigins, AllowMethods: []string{http.MethodGet, http.MethodHead, http.MethodPut, http.MethodPatch, http.MethodPost, http.MethodDelete}, }))