summaryrefslogtreecommitdiffstats
path: root/modules/setting/cors.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-01-29 15:47:46 +0800
committerGitHub <noreply@github.com>2020-01-29 09:47:46 +0200
commit79ce91fddee549514c98f002b719fc8cda0e380f (patch)
tree56271e8e73b238bfee415a64d73d1272c67fef3a /modules/setting/cors.go
parentc09e020558318feebbdce477f91c94411e8959b6 (diff)
downloadgitea-79ce91fddee549514c98f002b719fc8cda0e380f.tar.gz
gitea-79ce91fddee549514c98f002b719fc8cda0e380f.zip
Movde dependents on macaron from modules/setting (#10050)
Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'modules/setting/cors.go')
-rw-r--r--modules/setting/cors.go33
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")
}
}