Update CORS configuration in main.go
- Updated the handling of the ALLOWED_ORIGINS environment variable to ensure a default value of '*' is used when the variable is empty, improving the flexibility of CORS settings.
This commit is contained in:
6
main.go
6
main.go
@@ -58,7 +58,11 @@ func main() {
|
||||
|
||||
r := chi.NewRouter()
|
||||
|
||||
allowedOrigins := strings.Split(getEnv("ALLOWED_ORIGINS", "*"), ",")
|
||||
allowedOriginsStr := getEnv("ALLOWED_ORIGINS", "*")
|
||||
if allowedOriginsStr == "" {
|
||||
allowedOriginsStr = "*"
|
||||
}
|
||||
allowedOrigins := strings.Split(allowedOriginsStr, ",")
|
||||
r.Use(cors.Handler(cors.Options{
|
||||
AllowedOrigins: allowedOrigins,
|
||||
AllowedMethods: []string{"GET", "POST", "OPTIONS"},
|
||||
|
||||
Reference in New Issue
Block a user