Skip to content

Commit a67035b

Browse files
Merge pull request #17 from factly/web/remove-hardcoded-cors
server: update server no auth config example envs
2 parents a84a4ee + e27f47e commit a67035b

4 files changed

Lines changed: 7 additions & 87 deletions

File tree

config-noauth.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ GOPIE_S3_ENDPOINT=http://minio:9000
3030
GOPIE_S3_SSL=false
3131
GOPIE_S3_REGION=us-east-1
3232
GOPIE_DOWNLOADS_S3_BUCKET=downloads
33+
# Flag to determine if CORS is handled by ingress (true) or by the application (false)
34+
GOPIE_CORS_HANDLED_BY_INGRESS=false
35+
36+
3337

3438
# ==================================
3539
# Companion Service Configuration

server/.env.example

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,3 @@ GOPIE_AIAGENT_URL=http://localhost:8000
8080
## CORS CONFIGURATION
8181
# Flag to determine if CORS is handled by ingress (true) or by the application (false)
8282
GOPIE_CORS_HANDLED_BY_INGRESS=false
83-
84-
# Main server CORS settings
85-
GOPIE_MAIN_CORS_ALLOW_ORIGINS="http://localhost:3000"
86-
GOPIE_MAIN_CORS_ALLOW_METHODS="GET,POST,HEAD,PUT,DELETE,PATCH,OPTIONS"
87-
GOPIE_MAIN_CORS_ALLOW_HEADERS="Origin, Content-Type, Accept, Authorization, X-Requested-With, X-CSRF-Token, userID, x-user-id, x-project-ids, x-dataset-ids, x-chat-id, x-organization-id"
88-
GOPIE_MAIN_CORS_ALLOW_CREDENTIALS=true
89-
GOPIE_MAIN_CORS_MAX_AGE=86400
90-
91-
# Internal server CORS settings
92-
GOPIE_INTERNAL_CORS_ALLOW_ORIGINS="http://localhost:3000"
93-
GOPIE_INTERNAL_CORS_ALLOW_METHODS="GET,POST,HEAD,PUT,DELETE,PATCH,OPTIONS"
94-
GOPIE_INTERNAL_CORS_ALLOW_HEADERS="Origin, Content-Type, Accept, Authorization, X-Requested-With, X-CSRF-Token, userID, x-user-id, x-project-ids, x-dataset-ids, x-chat-id, x-organization-id"
95-
GOPIE_INTERNAL_CORS_ALLOW_CREDENTIALS=true
96-
GOPIE_INTERNAL_CORS_MAX_AGE=86400
97-
98-
# API server CORS settings
99-
GOPIE_API_CORS_ALLOW_ORIGINS="http://localhost:3000"
100-
GOPIE_API_CORS_ALLOW_METHODS="GET,POST,HEAD,PUT,DELETE,PATCH,OPTIONS"
101-
GOPIE_API_CORS_ALLOW_HEADERS="Origin, Content-Type, Accept, Authorization, X-Requested-With, X-CSRF-Token, userID, x-user-id, x-project-ids, x-dataset-ids, x-chat-id, x-organization-id"
102-
GOPIE_API_CORS_ALLOW_CREDENTIALS=true
103-
GOPIE_API_CORS_MAX_AGE=86400

server/domain/pkg/config/config.go

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ type GopieConfig struct {
6666
EnableZitadel bool
6767
DownloadsServer DownloadsConfig
6868
EncryptionKey string
69-
MainCORS CORSConfig
70-
InternalCORS CORSConfig
71-
APICORS CORSConfig
7269
CORSHandledByIngress bool
7370
}
7471

@@ -267,27 +264,6 @@ func setDefaults() {
267264
viper.SetDefault("GOPIE_MOTHERDUCK_HELPER_DB_DIR_PATH", "./motherduck")
268265
viper.SetDefault("GOPIE_DOWNLOADS_USE_SERVER", false)
269266

270-
// Default CORS settings for main server
271-
viper.SetDefault("GOPIE_MAIN_CORS_ALLOW_ORIGINS", "*")
272-
viper.SetDefault("GOPIE_MAIN_CORS_ALLOW_METHODS", "GET,POST,HEAD,PUT,DELETE,PATCH,OPTIONS")
273-
viper.SetDefault("GOPIE_MAIN_CORS_ALLOW_HEADERS", "Origin, Content-Type, Accept, Authorization, X-Requested-With, X-CSRF-Token, userID, x-user-id, x-project-ids, x-dataset-ids, x-chat-id, x-organization-id")
274-
viper.SetDefault("GOPIE_MAIN_CORS_ALLOW_CREDENTIALS", false)
275-
viper.SetDefault("GOPIE_MAIN_CORS_MAX_AGE", 86400)
276-
277-
// Default CORS settings for internal server
278-
viper.SetDefault("GOPIE_INTERNAL_CORS_ALLOW_ORIGINS", "*")
279-
viper.SetDefault("GOPIE_INTERNAL_CORS_ALLOW_METHODS", "GET,POST,HEAD,PUT,DELETE,PATCH,OPTIONS")
280-
viper.SetDefault("GOPIE_INTERNAL_CORS_ALLOW_HEADERS", "Origin, Content-Type, Accept, Authorization, X-Requested-With, X-CSRF-Token, userID, x-user-id, x-project-ids, x-dataset-ids, x-chat-id, x-organization-id")
281-
viper.SetDefault("GOPIE_INTERNAL_CORS_ALLOW_CREDENTIALS", false)
282-
viper.SetDefault("GOPIE_INTERNAL_CORS_MAX_AGE", 86400)
283-
284-
// Default CORS settings for API server
285-
viper.SetDefault("GOPIE_API_CORS_ALLOW_ORIGINS", "*")
286-
viper.SetDefault("GOPIE_API_CORS_ALLOW_METHODS", "GET,POST,HEAD,PUT,DELETE,PATCH,OPTIONS")
287-
viper.SetDefault("GOPIE_API_CORS_ALLOW_HEADERS", "Origin, Content-Type, Accept, Authorization, X-Requested-With, X-CSRF-Token, userID, x-user-id, x-project-ids, x-dataset-ids, x-chat-id, x-organization-id")
288-
viper.SetDefault("GOPIE_API_CORS_ALLOW_CREDENTIALS", false)
289-
viper.SetDefault("GOPIE_API_CORS_MAX_AGE", 86400)
290-
291267
// Flag to determine if CORS is handled by ingress (true) or by the application (false)
292268
viper.SetDefault("GOPIE_CORS_HANDLED_BY_INGRESS", false)
293269
}
@@ -359,27 +335,6 @@ func LoadConfig() (*GopieConfig, error) {
359335
DownloadsServer: DownloadsConfig{
360336
Bucket: viper.GetString("GOPIE_DOWNLOADS_S3_BUCKET"),
361337
},
362-
MainCORS: CORSConfig{
363-
AllowOrigins: viper.GetString("GOPIE_MAIN_CORS_ALLOW_ORIGINS"),
364-
AllowMethods: viper.GetString("GOPIE_MAIN_CORS_ALLOW_METHODS"),
365-
AllowHeaders: viper.GetString("GOPIE_MAIN_CORS_ALLOW_HEADERS"),
366-
AllowCredentials: viper.GetBool("GOPIE_MAIN_CORS_ALLOW_CREDENTIALS"),
367-
MaxAge: viper.GetInt("GOPIE_MAIN_CORS_MAX_AGE"),
368-
},
369-
InternalCORS: CORSConfig{
370-
AllowOrigins: viper.GetString("GOPIE_INTERNAL_CORS_ALLOW_ORIGINS"),
371-
AllowMethods: viper.GetString("GOPIE_INTERNAL_CORS_ALLOW_METHODS"),
372-
AllowHeaders: viper.GetString("GOPIE_INTERNAL_CORS_ALLOW_HEADERS"),
373-
AllowCredentials: viper.GetBool("GOPIE_INTERNAL_CORS_ALLOW_CREDENTIALS"),
374-
MaxAge: viper.GetInt("GOPIE_INTERNAL_CORS_MAX_AGE"),
375-
},
376-
APICORS: CORSConfig{
377-
AllowOrigins: viper.GetString("GOPIE_API_CORS_ALLOW_ORIGINS"),
378-
AllowMethods: viper.GetString("GOPIE_API_CORS_ALLOW_METHODS"),
379-
AllowHeaders: viper.GetString("GOPIE_API_CORS_ALLOW_HEADERS"),
380-
AllowCredentials: viper.GetBool("GOPIE_API_CORS_ALLOW_CREDENTIALS"),
381-
MaxAge: viper.GetInt("GOPIE_API_CORS_MAX_AGE"),
382-
},
383338
EncryptionKey: viper.GetString("GOPIE_ENCRYPTION_KEY"),
384339
}
385340

server/interfaces/http/serve.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,7 @@ func serve(cfg *config.GopieConfig, params *ServerParams, ctx context.Context) e
4747

4848
// Apply CORS middleware only if not handled by ingress
4949
if !cfg.CORSHandledByIngress {
50-
app.Use(cors.New(cors.Config{
51-
AllowOrigins: cfg.MainCORS.AllowOrigins,
52-
AllowMethods: cfg.MainCORS.AllowMethods,
53-
AllowHeaders: cfg.MainCORS.AllowHeaders,
54-
AllowCredentials: cfg.MainCORS.AllowCredentials,
55-
MaxAge: cfg.MainCORS.MaxAge,
56-
}))
50+
app.Use(cors.New(cors.Config{}))
5751
}
5852

5953
app.Use(fiberzap.New(fiberzap.Config{
@@ -172,13 +166,7 @@ func serveInternal(cfg *config.GopieConfig, params *ServerParams, ctx context.Co
172166

173167
// Apply CORS middleware only if not handled by ingress
174168
if !cfg.CORSHandledByIngress {
175-
app.Use(cors.New(cors.Config{
176-
AllowOrigins: cfg.InternalCORS.AllowOrigins,
177-
AllowMethods: cfg.InternalCORS.AllowMethods,
178-
AllowHeaders: cfg.InternalCORS.AllowHeaders,
179-
AllowCredentials: cfg.InternalCORS.AllowCredentials,
180-
MaxAge: cfg.InternalCORS.MaxAge,
181-
}))
169+
app.Use(cors.New(cors.Config{}))
182170
}
183171

184172
app.Use(fiberzap.New(fiberzap.Config{
@@ -251,13 +239,7 @@ func serveAPI(cfg *config.GopieConfig, params *ServerParams, ctx context.Context
251239

252240
// Apply CORS middleware only if not handled by ingress
253241
if !cfg.CORSHandledByIngress {
254-
app.Use(cors.New(cors.Config{
255-
AllowOrigins: cfg.APICORS.AllowOrigins,
256-
AllowMethods: cfg.APICORS.AllowMethods,
257-
AllowHeaders: cfg.APICORS.AllowHeaders,
258-
AllowCredentials: cfg.APICORS.AllowCredentials,
259-
MaxAge: cfg.APICORS.MaxAge,
260-
}))
242+
app.Use(cors.New(cors.Config{}))
261243
}
262244

263245
app.Use(fiberzap.New(fiberzap.Config{

0 commit comments

Comments
 (0)