You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cors.go 1013B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package setting
  5. import (
  6. "time"
  7. "code.gitea.io/gitea/modules/log"
  8. "gitea.com/macaron/cors"
  9. )
  10. var (
  11. // CORSConfig defines CORS settings
  12. CORSConfig cors.Options
  13. // EnableCORS defines whether CORS settings is enabled or not
  14. EnableCORS bool
  15. )
  16. func newCORSService() {
  17. sec := Cfg.Section("cors")
  18. // Check cors setting.
  19. EnableCORS = sec.Key("ENABLED").MustBool(false)
  20. maxAge := sec.Key("MAX_AGE").MustDuration(10 * time.Minute)
  21. CORSConfig = cors.Options{
  22. Scheme: sec.Key("SCHEME").String(),
  23. AllowDomain: sec.Key("ALLOW_DOMAIN").Strings(","),
  24. AllowSubdomain: sec.Key("ALLOW_SUBDOMAIN").MustBool(),
  25. Methods: sec.Key("METHODS").Strings(","),
  26. MaxAgeSeconds: int(maxAge.Seconds()),
  27. AllowCredentials: sec.Key("ALLOW_CREDENTIALS").MustBool(),
  28. }
  29. if EnableCORS {
  30. log.Info("CORS Service Enabled")
  31. }
  32. }