mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-01-23 02:54:27 +00:00
refactor(cors): 🛠️ improve host handling in CORS config
* Change loop to use index for server instances * Simplify appending external URLs * Clean up commented code for clarity
This commit is contained in:
@@ -24,13 +24,12 @@ func DefaultCORSConfig() CORSConfig {
|
||||
|
||||
_, _, 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))
|
||||
|
||||
@@ -110,13 +110,13 @@ func (sc *ServersConfig) GetDefault() (*ServerInstanceConfig, error) {
|
||||
}
|
||||
|
||||
// GetIPs - GetIP for pc
|
||||
func GetIPs() (string, string, []net.IP) {
|
||||
func GetIPs() (hostname string, ipList string, ipNetList []net.IP) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
fmt.Println("Recovered in GetIPs", err)
|
||||
}
|
||||
}()
|
||||
hostname, _ := os.Hostname()
|
||||
hostname, _ = os.Hostname()
|
||||
ipaddrlist := make([]net.IP, 0)
|
||||
iplist := ""
|
||||
addrs, err := net.LookupIP(hostname)
|
||||
|
||||
Reference in New Issue
Block a user