refactor(cors): 🛠️ improve host handling in CORS config
Some checks failed
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in -27m44s
Build , Vet Test, and Lint / Lint Code (push) Successful in -27m5s
Build , Vet Test, and Lint / Build (push) Successful in -27m29s
Tests / Unit Tests (push) Successful in -27m48s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in 2m22s
Tests / Integration Tests (push) Failing after -28m1s

* Change loop to use index for server instances
* Simplify appending external URLs
* Clean up commented code for clarity
This commit is contained in:
Hein
2026-01-06 14:07:56 +02:00
parent 987244019c
commit 6ea200bb2b
2 changed files with 8 additions and 9 deletions

View File

@@ -20,17 +20,16 @@ func DefaultCORSConfig() CORSConfig {
configManager := config.GetConfigManager()
cfg, _ := configManager.GetConfig()
hosts := make([]string, 0)
//hosts = append(hosts, "*")
// hosts = append(hosts, "*")
_, _, ipsList := config.GetIPs()
for _, server := range cfg.Servers.Instances {
for i := range cfg.Servers.Instances {
server := cfg.Servers.Instances[i]
hosts = append(hosts, fmt.Sprintf("http://%s:%d", server.Host, server.Port))
hosts = append(hosts, fmt.Sprintf("https://%s:%d", server.Host, server.Port))
hosts = append(hosts, fmt.Sprintf("http://%s:%d", "localhost", server.Port))
for _, extURL := range server.ExternalURLs {
hosts = append(hosts, extURL)
}
hosts = append(hosts, server.ExternalURLs...)
for _, ip := range ipsList {
hosts = append(hosts, fmt.Sprintf("http://%s:%d", ip.String(), server.Port))
hosts = append(hosts, fmt.Sprintf("https://%s:%d", ip.String(), server.Port))