add automatic localhost and local ip for allowOrigin

This commit is contained in:
Adrian Zuercher
2025-06-29 21:26:16 +02:00
parent c58dbf34d0
commit e320156a47
4 changed files with 48 additions and 6 deletions

22
backend/utils/ip.go Normal file
View File

@@ -0,0 +1,22 @@
package utils
import (
"fmt"
"net"
)
func GetLocalIP() (string, error) {
addrs, err := net.InterfaceAddrs()
if err != nil {
return "", err
}
for _, addr := range addrs {
if ipNet, ok := addr.(*net.IPNet); ok && !ipNet.IP.IsLoopback() {
if ipNet.IP.To4() != nil {
return ipNet.IP.String(), nil
}
}
}
return "", fmt.Errorf("no local IP address found")
}