init security, add cors
This commit is contained in:
No files matched your search
@@ -20,6 +20,9 @@ func LoadConfig() *Config {
|
||||
Mode: getEnv("GIN_MODE", "debug"),
|
||||
},
|
||||
Databases: make(map[string]DatabaseConfig),
|
||||
Security: SecurityConfig{
|
||||
TrustedOrigins: parseOrigins(getEnv("SECURITY_TRUSTED_ORIGINS", "http://localhost:3000,http://localhost:8080")),
|
||||
},
|
||||
}
|
||||
|
||||
config.loadCustomDatabaseConfigs()
|
||||
|
||||
@@ -3,6 +3,7 @@ package config
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -155,3 +156,14 @@ func parseDuration(durationStr string) time.Duration {
|
||||
}
|
||||
return 5 * time.Minute
|
||||
}
|
||||
|
||||
func parseOrigins(originsStr string) []string {
|
||||
if originsStr == "" {
|
||||
return []string{"http://localhost:8080"} // Default untuk pengembangan
|
||||
}
|
||||
origins := strings.Split(originsStr, ",")
|
||||
for i, origin := range origins {
|
||||
origins[i] = strings.TrimSpace(origin)
|
||||
}
|
||||
return origins
|
||||
}
|
||||
@@ -6,6 +6,7 @@ type Config struct {
|
||||
Server ServerConfig
|
||||
Databases map[string]DatabaseConfig
|
||||
ReadReplicas map[string][]DatabaseConfig
|
||||
Security SecurityConfig
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
@@ -43,3 +44,7 @@ type DatabaseConfig struct {
|
||||
MaxIdleTime time.Duration // Maximum amount of time a connection may be idle
|
||||
HealthCheckPeriod time.Duration // Health check period
|
||||
}
|
||||
|
||||
type SecurityConfig struct {
|
||||
TrustedOrigins []string `mapstructure:"trusted_origins"`
|
||||
}
|
||||
Reference in New Issue
Block a user