diff --git a/.env.example b/.env.example index 79ad10a..ed8fe46 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,7 @@ OWNER_NPUB="npub1utx00neqgqln72j22kej3ux7803c2k986henvvha4thuwfkper4s7r50e8" RELAY_URL="relay.utxo.one" +RELAY_PORT=3355 +RELAY_BIND_ADDRESS="0.0.0.0" # Can be set to a specific IP4 or IP6 address ("" for all interfaces) DB_ENGINE="badger" # badger, lmdb (lmdb works best with an nvme, otherwise you might have stability issues) ## Private Relay Settings diff --git a/config.go b/config.go index 5d9c17f..6b2bb4b 100644 --- a/config.go +++ b/config.go @@ -14,6 +14,8 @@ type Config struct { OwnerNpub string `json:"owner_npub"` DBEngine string `json:"db_engine"` RelayURL string `json:"relay_url"` + RelayPort int `json:"relay_port"` + RelayBindAddress string `json:"relay_bind_address"` RelaySoftware string `json:"relay_software"` RelayVersion string `json:"relay_version"` PrivateRelayName string `json:"private_relay_name"` @@ -52,15 +54,14 @@ type AwsConfig struct { } func loadConfig() Config { - godotenv.Load(".env") - if os.Getenv("DB_ENGINE") == "" { - os.Setenv("DB_ENGINE", "lmdb") - } + _ = godotenv.Load(".env") return Config{ OwnerNpub: getEnv("OWNER_NPUB"), - DBEngine: getEnv("DB_ENGINE"), + DBEngine: getEnvString("DB_ENGINE", "lmdb"), RelayURL: getEnv("RELAY_URL"), + RelayPort: getEnvInt("RELAY_PORT", 3355), + RelayBindAddress: getEnvString("RELAY_BIND_ADDRESS", "0.0.0.0"), RelaySoftware: "https://github.com/bitvora/haven", RelayVersion: "v0.4.4", PrivateRelayName: getEnv("PRIVATE_RELAY_NAME"), @@ -121,6 +122,13 @@ func getEnv(key string) string { return value } +func getEnvString(key string, defaultValue string) string { + if value, ok := os.LookupEnv(key); ok { + return value + } + return defaultValue +} + func getEnvInt(key string, defaultValue int) int { if value, ok := os.LookupEnv(key); ok { intValue, err := strconv.Atoi(value) diff --git a/main.go b/main.go index da5bdbb..3724d99 100644 --- a/main.go +++ b/main.go @@ -48,8 +48,10 @@ func main() { http.HandleFunc("/", dynamicRelayHandler) - log.Printf("🔗 listening at http://localhost:3355") - http.ListenAndServe("0.0.0.0:3355", nil) + addr := fmt.Sprintf("%s:%d", config.RelayBindAddress, config.RelayPort) + + log.Printf("🔗 listening at %s", addr) + http.ListenAndServe(addr, nil) } func dynamicRelayHandler(w http.ResponseWriter, r *http.Request) {