diff options
Diffstat (limited to 'modules/setting/cors.go')
-rw-r--r-- | modules/setting/cors.go | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/modules/setting/cors.go b/modules/setting/cors.go index 04f3120536..d7856e8b23 100644 --- a/modules/setting/cors.go +++ b/modules/setting/cors.go @@ -8,34 +8,31 @@ import ( "time" "code.gitea.io/gitea/modules/log" - - "gitea.com/macaron/cors" ) var ( // CORSConfig defines CORS settings - CORSConfig cors.Options - // EnableCORS defines whether CORS settings is enabled or not - EnableCORS bool + CORSConfig = struct { + Enabled bool + Scheme string + AllowDomain []string + AllowSubdomain bool + Methods []string + MaxAge time.Duration + AllowCredentials bool + }{ + Enabled: false, + MaxAge: 10 * time.Minute, + } ) func newCORSService() { sec := Cfg.Section("cors") - // Check cors setting. - EnableCORS = sec.Key("ENABLED").MustBool(false) - - maxAge := sec.Key("MAX_AGE").MustDuration(10 * time.Minute) - - CORSConfig = cors.Options{ - Scheme: sec.Key("SCHEME").String(), - AllowDomain: sec.Key("ALLOW_DOMAIN").Strings(","), - AllowSubdomain: sec.Key("ALLOW_SUBDOMAIN").MustBool(), - Methods: sec.Key("METHODS").Strings(","), - MaxAgeSeconds: int(maxAge.Seconds()), - AllowCredentials: sec.Key("ALLOW_CREDENTIALS").MustBool(), + if err := sec.MapTo(&CORSConfig); err != nil { + log.Fatal("Failed to map cors settings: %v", err) } - if EnableCORS { + if CORSConfig.Enabled { log.Info("CORS Service Enabled") } } |