Fix CORS middleware panic and add Procfile

- Transform ALLOWED_HOSTS to proper origins with http/https prefix
- Fallback to AllowAllOrigins if no valid origins configured
- Add Procfile for dokku process types

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-11-26 20:28:13 -06:00
parent eea53c09b2
commit 440104bad6
2 changed files with 28 additions and 2 deletions

2
Procfile Normal file
View File

@@ -0,0 +1,2 @@
web: /app/api
worker: /app/worker

View File

@@ -124,11 +124,35 @@ func corsMiddleware(cfg *config.Config) gin.HandlerFunc {
MaxAge: 12 * time.Hour,
}
// In debug mode, allow all origins; otherwise use configured hosts
// In debug mode or if no proper origins configured, allow all origins
if cfg.Server.Debug {
corsConfig.AllowAllOrigins = true
} else {
corsConfig.AllowOrigins = cfg.Server.AllowedHosts
// Transform allowed hosts to proper origins with https://
var origins []string
for _, host := range cfg.Server.AllowedHosts {
host = strings.TrimSpace(host)
if host == "" {
continue
}
if host == "*" {
corsConfig.AllowAllOrigins = true
break
}
// If host doesn't have scheme, add https://
if !strings.HasPrefix(host, "http://") && !strings.HasPrefix(host, "https://") {
origins = append(origins, "https://"+host)
origins = append(origins, "http://"+host) // Also allow http for dev
} else {
origins = append(origins, host)
}
}
if !corsConfig.AllowAllOrigins && len(origins) > 0 {
corsConfig.AllowOrigins = origins
} else if !corsConfig.AllowAllOrigins {
// Fallback to allow all if no valid origins
corsConfig.AllowAllOrigins = true
}
}
return cors.New(corsConfig)