1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-02-06 10:44:43 +00:00

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

@ -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.
//

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
}

View File

@ -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},
}))