From e5098c803523dfee552a9b5e7d7a91f435d691eb Mon Sep 17 00:00:00 2001 From: Debian Date: Wed, 3 Sep 2025 18:27:26 +0000 Subject: [PATCH] fix: Read relay URLs from TOML config file instead of hardcoded localhost:8090 --- src/config.ts | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index caa0e80..47ec061 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,4 +1,6 @@ import dotenv from 'dotenv'; +import * as fs from 'fs'; +import * as path from 'path'; // Load environment variables from .env file dotenv.config(); @@ -13,12 +15,50 @@ export interface AppConfig { logLevel: string; } +function parseConfigFile(): Partial { + try { + // Try to read the TOML config file + const configPath = '/usr/local/bin/sdk_signer.conf'; + if (fs.existsSync(configPath)) { + const configContent = fs.readFileSync(configPath, 'utf8'); + + // Simple TOML parsing for our needs + const relayUrlsMatch = configContent.match(/relay_urls\s*=\s*\[(.*?)\]/); + const wsPortMatch = configContent.match(/ws_port\s*=\s*(\d+)/); + const httpPortMatch = configContent.match(/http_port\s*=\s*(\d+)/); + + const config: Partial = {}; + + if (relayUrlsMatch) { + // Parse relay URLs from the array format + const urlsStr = relayUrlsMatch[1]; + const urls = urlsStr.split(',').map(url => + url.trim().replace(/"/g, '').replace(/http:\/\//, 'ws://') + ); + config.relayUrls = urls; + } + + if (wsPortMatch) { + config.port = parseInt(wsPortMatch[1]); + } + + return config; + } + } catch (error) { + console.warn('⚠️ Warning: Could not read config file, using defaults:', error); + } + + return {}; +} + export function loadConfig(): AppConfig { + const fileConfig = parseConfigFile(); + return { - port: parseInt(process.env.PORT || '9090'), + port: fileConfig.port || parseInt(process.env.PORT || '9090'), apiKey: process.env.API_KEY || 'your-api-key-change-this', databasePath: process.env.DATABASE_PATH || './data/server.db', - relayUrls: process.env.RELAY_URLS?.split(',') || ['ws://localhost:8090'], + relayUrls: fileConfig.relayUrls || process.env.RELAY_URLS?.split(',') || ['ws://localhost:8090'], autoRestart: process.env.AUTO_RESTART === 'true', maxRestarts: parseInt(process.env.MAX_RESTARTS || '10'), logLevel: process.env.LOG_LEVEL || 'info'