MCPcopy
hub / github.com/gotify/server / CorsConfig

Function CorsConfig

auth/cors.go:14–44  ·  view source on GitHub ↗

CorsConfig generates a config to use in gin cors middleware based on server configuration.

(conf *config.Configuration)

Source from the content-addressed store, hash-verified

12
13// CorsConfig generates a config to use in gin cors middleware based on server configuration.
14func CorsConfig(conf *config.Configuration) cors.Config {
15 corsConf := cors.Config{
16 MaxAge: 12 * time.Hour,
17 AllowBrowserExtensions: true,
18 }
19 if mode.IsDev() {
20 corsConf.AllowAllOrigins = true
21 corsConf.AllowMethods = []string{"GET", "POST", "DELETE", "OPTIONS", "PUT"}
22 corsConf.AllowHeaders = []string{
23 "X-Gotify-Key", "Authorization", "Content-Type", "Upgrade", "Origin",
24 "Connection", "Accept-Encoding", "Accept-Language", "Host",
25 }
26 } else {
27 compiledOrigins := compileAllowedCORSOrigins(conf.Server.Cors.AllowOrigins)
28 corsConf.AllowMethods = conf.Server.Cors.AllowMethods
29 corsConf.AllowHeaders = conf.Server.Cors.AllowHeaders
30 corsConf.AllowOriginFunc = func(origin string) bool {
31 for _, compiledOrigin := range compiledOrigins {
32 if compiledOrigin.MatchString(strings.ToLower(origin)) {
33 return true
34 }
35 }
36 return false
37 }
38 if allowedOrigin := headerIgnoreCase(conf, "access-control-allow-origin"); allowedOrigin != "" && len(compiledOrigins) == 0 {
39 corsConf.AllowOrigins = append(corsConf.AllowOrigins, allowedOrigin)
40 }
41 }
42
43 return corsConf
44}
45
46func headerIgnoreCase(conf *config.Configuration, search string) (value string) {
47 for key, value := range conf.Server.ResponseHeaders {

Callers 4

CreateFunction · 0.92
TestCorsConfigFunction · 0.85
TestDevCorsConfigFunction · 0.85

Calls 3

IsDevFunction · 0.92
headerIgnoreCaseFunction · 0.85

Tested by 3

TestCorsConfigFunction · 0.68
TestDevCorsConfigFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…