github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/setting/cors.go (about)

     1  // Copyright 2023 The GitBundle Inc. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // Use of this source code is governed by a MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package setting
     7  
     8  import (
     9  	"time"
    10  
    11  	"github.com/gitbundle/modules/log"
    12  )
    13  
    14  // CORSConfig defines CORS settings
    15  var CORSConfig = struct {
    16  	Enabled          bool
    17  	Scheme           string
    18  	AllowDomain      []string
    19  	AllowSubdomain   bool
    20  	Methods          []string
    21  	MaxAge           time.Duration
    22  	AllowCredentials bool
    23  	XFrameOptions    string
    24  }{
    25  	Enabled:       false,
    26  	MaxAge:        10 * time.Minute,
    27  	XFrameOptions: "SAMEORIGIN",
    28  }
    29  
    30  func newCORSService() {
    31  	sec := Cfg.Section("cors")
    32  	if err := sec.MapTo(&CORSConfig); err != nil {
    33  		log.Fatal("Failed to map cors settings: %v", err)
    34  	}
    35  
    36  	if CORSConfig.Enabled {
    37  		log.Info("CORS Service Enabled")
    38  	}
    39  }