mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Added FN_API_CORS_HEADERS for configuring CORS headers (#997)
This commit is contained in:
committed by
Alexander Bransby-Sharples
parent
37354838b4
commit
19f09b3a6c
@@ -22,12 +22,22 @@ func optionalCorsWrap(r *gin.Engine) {
|
||||
// By default no CORS are allowed unless one
|
||||
// or more Origins are defined by the API_CORS
|
||||
// environment variable.
|
||||
corsStr := getEnv(EnvAPICORS, "")
|
||||
corsStr := getEnv(EnvAPICORSOrigins, "")
|
||||
if len(corsStr) > 0 {
|
||||
origins := strings.Split(strings.Replace(corsStr, " ", "", -1), ",")
|
||||
|
||||
corsConfig := cors.DefaultConfig()
|
||||
corsConfig.AllowOrigins = origins
|
||||
if origins[0] == "*" {
|
||||
corsConfig.AllowAllOrigins = true
|
||||
} else {
|
||||
corsConfig.AllowOrigins = origins
|
||||
}
|
||||
|
||||
corsHeaders := getEnv(EnvAPICORSHeaders, "")
|
||||
if len(corsHeaders) > 0 {
|
||||
headers := strings.Split(strings.Replace(corsHeaders, " ", "", -1), ",")
|
||||
corsConfig.AllowHeaders = headers
|
||||
}
|
||||
|
||||
logrus.Infof("CORS enabled for domains: %s", origins)
|
||||
|
||||
|
||||
@@ -54,7 +54,8 @@ const (
|
||||
EnvNodeType = "FN_NODE_TYPE"
|
||||
EnvPort = "FN_PORT" // be careful, Gin expects this variable to be "port"
|
||||
EnvGRPCPort = "FN_GRPC_PORT"
|
||||
EnvAPICORS = "FN_API_CORS"
|
||||
EnvAPICORSOrigins = "FN_API_CORS_ORIGINS"
|
||||
EnvAPICORSHeaders = "FN_API_CORS_HEADERS"
|
||||
EnvZipkinURL = "FN_ZIPKIN_URL"
|
||||
EnvJaegerURL = "FN_JAEGER_URL"
|
||||
// Certificates to communicate with other FN nodes
|
||||
|
||||
Reference in New Issue
Block a user