mirror of
https://github.com/gogs/gogs.git
synced 2025-05-31 11:42:13 +00:00
Able to set custom Access-Control-Allow-Origin header (#3987)
Added new config option '[http] ACCESS_CONTROL_ALLOW_ORIGIN'.
This commit is contained in:
parent
c98aa0e895
commit
5e01ecbc05
14
cmd/web.go
14
cmd/web.go
@ -99,7 +99,7 @@ func checkVersion() {
|
|||||||
for _, c := range checkers {
|
for _, c := range checkers {
|
||||||
if !version.Compare(c.Version(), c.Expected, ">=") {
|
if !version.Compare(c.Version(), c.Expected, ">=") {
|
||||||
log.Fatal(4, `Dependency outdated!
|
log.Fatal(4, `Dependency outdated!
|
||||||
Package '%s' current version (%s) is below requirement (%s),
|
Package '%s' current version (%s) is below requirement (%s),
|
||||||
please use following command to update this package and recompile Gogs:
|
please use following command to update this package and recompile Gogs:
|
||||||
go get -u %[1]s`, c.ImportPath, c.Version(), c.Expected)
|
go get -u %[1]s`, c.ImportPath, c.Version(), c.Expected)
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ func newMacaron() *macaron.Macaron {
|
|||||||
if setting.EnableGzip {
|
if setting.EnableGzip {
|
||||||
m.Use(gzip.Gziper())
|
m.Use(gzip.Gziper())
|
||||||
}
|
}
|
||||||
if setting.Protocol == setting.FCGI {
|
if setting.Protocol == setting.SCHEME_FCGI {
|
||||||
m.SetURLPrefix(setting.AppSubUrl)
|
m.SetURLPrefix(setting.AppSubUrl)
|
||||||
}
|
}
|
||||||
m.Use(macaron.Static(
|
m.Use(macaron.Static(
|
||||||
@ -640,7 +640,7 @@ func runWeb(ctx *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var listenAddr string
|
var listenAddr string
|
||||||
if setting.Protocol == setting.UNIX_SOCKET {
|
if setting.Protocol == setting.SCHEME_UNIX_SOCKET {
|
||||||
listenAddr = fmt.Sprintf("%s", setting.HTTPAddr)
|
listenAddr = fmt.Sprintf("%s", setting.HTTPAddr)
|
||||||
} else {
|
} else {
|
||||||
listenAddr = fmt.Sprintf("%s:%s", setting.HTTPAddr, setting.HTTPPort)
|
listenAddr = fmt.Sprintf("%s:%s", setting.HTTPAddr, setting.HTTPPort)
|
||||||
@ -649,14 +649,14 @@ func runWeb(ctx *cli.Context) error {
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
switch setting.Protocol {
|
switch setting.Protocol {
|
||||||
case setting.HTTP:
|
case setting.SCHEME_HTTP:
|
||||||
err = http.ListenAndServe(listenAddr, m)
|
err = http.ListenAndServe(listenAddr, m)
|
||||||
case setting.HTTPS:
|
case setting.SCHEME_HTTPS:
|
||||||
server := &http.Server{Addr: listenAddr, TLSConfig: &tls.Config{MinVersion: tls.VersionTLS10}, Handler: m}
|
server := &http.Server{Addr: listenAddr, TLSConfig: &tls.Config{MinVersion: tls.VersionTLS10}, Handler: m}
|
||||||
err = server.ListenAndServeTLS(setting.CertFile, setting.KeyFile)
|
err = server.ListenAndServeTLS(setting.CertFile, setting.KeyFile)
|
||||||
case setting.FCGI:
|
case setting.SCHEME_FCGI:
|
||||||
err = fcgi.Serve(nil, m)
|
err = fcgi.Serve(nil, m)
|
||||||
case setting.UNIX_SOCKET:
|
case setting.SCHEME_UNIX_SOCKET:
|
||||||
os.Remove(listenAddr)
|
os.Remove(listenAddr)
|
||||||
|
|
||||||
var listener *net.UnixListener
|
var listener *net.UnixListener
|
||||||
|
@ -142,6 +142,10 @@ ENABLE_GZIP = false
|
|||||||
; Landing page for non-logged users, can be "home" or "explore"
|
; Landing page for non-logged users, can be "home" or "explore"
|
||||||
LANDING_PAGE = home
|
LANDING_PAGE = home
|
||||||
|
|
||||||
|
[http]
|
||||||
|
; Value for Access-Control-Allow-Origin header, default is not to present
|
||||||
|
ACCESS_CONTROL_ALLOW_ORIGIN =
|
||||||
|
|
||||||
; Define allowed algorithms and their minimum key length (use -1 to disable a type)
|
; Define allowed algorithms and their minimum key length (use -1 to disable a type)
|
||||||
[ssh.minimum_key_sizes]
|
[ssh.minimum_key_sizes]
|
||||||
ED25519 = 256
|
ED25519 = 256
|
||||||
|
2
gogs.go
2
gogs.go
@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.9.123.0128"
|
const APP_VER = "0.9.124.0128"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
setting.AppVer = APP_VER
|
setting.AppVer = APP_VER
|
||||||
|
File diff suppressed because one or more lines are too long
@ -156,6 +156,11 @@ func Contexter() macaron.Handler {
|
|||||||
},
|
},
|
||||||
Org: &Organization{},
|
Org: &Organization{},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(setting.HTTP.AccessControlAllowOrigin) > 0 {
|
||||||
|
ctx.Header().Set("Access-Control-Allow-Origin", setting.HTTP.AccessControlAllowOrigin)
|
||||||
|
}
|
||||||
|
|
||||||
// Compute current URL for real-time change language.
|
// Compute current URL for real-time change language.
|
||||||
ctx.Data["Link"] = setting.AppSubUrl + strings.TrimSuffix(ctx.Req.URL.Path, "/")
|
ctx.Data["Link"] = setting.AppSubUrl + strings.TrimSuffix(ctx.Req.URL.Path, "/")
|
||||||
|
|
||||||
|
@ -34,10 +34,10 @@ import (
|
|||||||
type Scheme string
|
type Scheme string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
HTTP Scheme = "http"
|
SCHEME_HTTP Scheme = "http"
|
||||||
HTTPS Scheme = "https"
|
SCHEME_HTTPS Scheme = "https"
|
||||||
FCGI Scheme = "fcgi"
|
SCHEME_FCGI Scheme = "fcgi"
|
||||||
UNIX_SOCKET Scheme = "unix"
|
SCHEME_UNIX_SOCKET Scheme = "unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LandingPage string
|
type LandingPage string
|
||||||
@ -74,6 +74,10 @@ var (
|
|||||||
LandingPageURL LandingPage
|
LandingPageURL LandingPage
|
||||||
UnixSocketPermission uint32
|
UnixSocketPermission uint32
|
||||||
|
|
||||||
|
HTTP struct {
|
||||||
|
AccessControlAllowOrigin string
|
||||||
|
}
|
||||||
|
|
||||||
SSH struct {
|
SSH struct {
|
||||||
Disabled bool `ini:"DISABLE_SSH"`
|
Disabled bool `ini:"DISABLE_SSH"`
|
||||||
StartBuiltinServer bool `ini:"START_SSH_SERVER"`
|
StartBuiltinServer bool `ini:"START_SSH_SERVER"`
|
||||||
@ -388,15 +392,15 @@ func NewContext() {
|
|||||||
AppSubUrl = strings.TrimSuffix(url.Path, "/")
|
AppSubUrl = strings.TrimSuffix(url.Path, "/")
|
||||||
AppSubUrlDepth = strings.Count(AppSubUrl, "/")
|
AppSubUrlDepth = strings.Count(AppSubUrl, "/")
|
||||||
|
|
||||||
Protocol = HTTP
|
Protocol = SCHEME_HTTP
|
||||||
if sec.Key("PROTOCOL").String() == "https" {
|
if sec.Key("PROTOCOL").String() == "https" {
|
||||||
Protocol = HTTPS
|
Protocol = SCHEME_HTTPS
|
||||||
CertFile = sec.Key("CERT_FILE").String()
|
CertFile = sec.Key("CERT_FILE").String()
|
||||||
KeyFile = sec.Key("KEY_FILE").String()
|
KeyFile = sec.Key("KEY_FILE").String()
|
||||||
} else if sec.Key("PROTOCOL").String() == "fcgi" {
|
} else if sec.Key("PROTOCOL").String() == "fcgi" {
|
||||||
Protocol = FCGI
|
Protocol = SCHEME_FCGI
|
||||||
} else if sec.Key("PROTOCOL").String() == "unix" {
|
} else if sec.Key("PROTOCOL").String() == "unix" {
|
||||||
Protocol = UNIX_SOCKET
|
Protocol = SCHEME_UNIX_SOCKET
|
||||||
UnixSocketPermissionRaw := sec.Key("UNIX_SOCKET_PERMISSION").MustString("666")
|
UnixSocketPermissionRaw := sec.Key("UNIX_SOCKET_PERMISSION").MustString("666")
|
||||||
UnixSocketPermissionParsed, err := strconv.ParseUint(UnixSocketPermissionRaw, 8, 32)
|
UnixSocketPermissionParsed, err := strconv.ParseUint(UnixSocketPermissionRaw, 8, 32)
|
||||||
if err != nil || UnixSocketPermissionParsed > 0777 {
|
if err != nil || UnixSocketPermissionParsed > 0777 {
|
||||||
@ -557,7 +561,9 @@ func NewContext() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = Cfg.Section("ui").MapTo(&UI); err != nil {
|
if err = Cfg.Section("http").MapTo(&HTTP); err != nil {
|
||||||
|
log.Fatal(4, "Fail to map HTTP settings: %v", err)
|
||||||
|
} else if err = Cfg.Section("ui").MapTo(&UI); err != nil {
|
||||||
log.Fatal(4, "Fail to map UI settings: %v", err)
|
log.Fatal(4, "Fail to map UI settings: %v", err)
|
||||||
} else if err = Cfg.Section("markdown").MapTo(&Markdown); err != nil {
|
} else if err = Cfg.Section("markdown").MapTo(&Markdown); err != nil {
|
||||||
log.Fatal(4, "Fail to map Markdown settings: %v", err)
|
log.Fatal(4, "Fail to map Markdown settings: %v", err)
|
||||||
|
@ -1 +1 @@
|
|||||||
0.9.123.0128
|
0.9.124.0128
|
Loading…
x
Reference in New Issue
Block a user