fix: Read relay URLs from TOML config file instead of hardcoded localhost:8090
This commit is contained in:
parent
5ad528a701
commit
e5098c8035
@ -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<AppConfig> {
|
||||
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<AppConfig> = {};
|
||||
|
||||
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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user