add cors support
This commit is contained in:
@@ -36,6 +36,8 @@ var testDefaultConfig = &AppConfig{
|
||||
LogRequests: false,
|
||||
EnableReflection: true,
|
||||
EnableInstrumentation: true,
|
||||
EnableGRPCGateway: true,
|
||||
GRPCGatewayPath: "/grpc-api",
|
||||
},
|
||||
OTEL: &OTELConfig{
|
||||
Enabled: true,
|
||||
@@ -90,6 +92,8 @@ func Test_loadConfig(t *testing.T) {
|
||||
LogRequests: false,
|
||||
EnableReflection: true,
|
||||
EnableInstrumentation: true,
|
||||
EnableGRPCGateway: true,
|
||||
GRPCGatewayPath: "/grpc-api",
|
||||
},
|
||||
OTEL: &OTELConfig{
|
||||
Enabled: true,
|
||||
@@ -128,6 +132,8 @@ func Test_loadConfig(t *testing.T) {
|
||||
LogRequests: true,
|
||||
EnableReflection: false,
|
||||
EnableInstrumentation: false,
|
||||
EnableGRPCGateway: true,
|
||||
GRPCGatewayPath: "/grpc-api",
|
||||
},
|
||||
OTEL: &OTELConfig{
|
||||
Enabled: false,
|
||||
|
||||
@@ -14,6 +14,8 @@ var defaultHTTPConfig = &HTTPConfig{
|
||||
ReadTimeout: "10s",
|
||||
WriteTimeout: "10s",
|
||||
IdleTimeout: "1m",
|
||||
|
||||
CORSEnabled: false,
|
||||
}
|
||||
|
||||
// HTTPConfig provides HTTP server Configuration
|
||||
@@ -25,11 +27,18 @@ type HTTPConfig struct {
|
||||
ReadTimeout string `yaml:"readTimeout" env:"APP_HTTP_READ_TIMEOUT" json:"readTimeout,omitempty"` // Go duration (e.g. 10s)
|
||||
WriteTimeout string `yaml:"writeTimeout" env:"APP_HTTP_WRITE_TIMEOUT" json:"writeTimeout,omitempty"` // Go duration (e.g. 10s)
|
||||
IdleTimeout string `yaml:"idleTimeout" env:"APP_HTTP_IDLE_TIMEOUT" json:"idleTimeout,omitempty"` // Go duration (e.g. 10s)
|
||||
excludeRegexps []*regexp.Regexp
|
||||
rT *time.Duration
|
||||
wT *time.Duration
|
||||
iT *time.Duration
|
||||
lock sync.RWMutex
|
||||
|
||||
// CORS configuration
|
||||
CORSEnabled bool `yaml:"corsEnabled" env:"APP_HTTP_CORS_ENABLED" json:"corsEnabled,omitempty"`
|
||||
CORSAllowedOrigins []string `yaml:"corsAllowedOrigins" env:"APP_HTTP_CORS_ALLOWED_ORIGINS" json:"corsAllowedOrigins,omitempty"` // Defaults to ["*"] if empty and CORS enabled
|
||||
CORSAllowCredentials bool `yaml:"corsAllowCredentials" env:"APP_HTTP_CORS_ALLOW_CREDENTIALS" json:"corsAllowCredentials,omitempty"` // Allow credentials (cookies, auth headers)
|
||||
CORSAllowPrivateNetwork bool `yaml:"corsAllowPrivateNetwork" env:"APP_HTTP_CORS_ALLOW_PRIVATE_NETWORK" json:"corsAllowPrivateNetwork,omitempty"` // Allow requests from private networks
|
||||
|
||||
excludeRegexps []*regexp.Regexp
|
||||
rT *time.Duration
|
||||
wT *time.Duration
|
||||
iT *time.Duration
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
func (h *HTTPConfig) GetExcludeRegexps() []*regexp.Regexp {
|
||||
|
||||
Reference in New Issue
Block a user