Spaces:
Sleeping
Sleeping
| import { readFileSync, existsSync } from 'fs'; | |
| import { resolve, dirname } from 'path'; | |
| import { fileURLToPath } from 'url'; | |
| const __dirname = dirname(fileURLToPath(import.meta.url)); | |
| const ROOT = resolve(__dirname, '..'); | |
| // Load .env file manually (zero dependencies) | |
| function loadEnv() { | |
| const envPath = resolve(ROOT, '.env'); | |
| if (!existsSync(envPath)) return; | |
| const content = readFileSync(envPath, 'utf-8'); | |
| for (const line of content.split('\n')) { | |
| const trimmed = line.trim(); | |
| if (!trimmed || trimmed.startsWith('#')) continue; | |
| const eqIdx = trimmed.indexOf('='); | |
| if (eqIdx === -1) continue; | |
| const key = trimmed.slice(0, eqIdx).trim(); | |
| let val = trimmed.slice(eqIdx + 1).trim(); | |
| if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) { | |
| val = val.slice(1, -1); | |
| } | |
| if (!process.env[key]) { | |
| process.env[key] = val; | |
| } | |
| } | |
| } | |
| loadEnv(); | |
| export const config = { | |
| port: parseInt(process.env.PORT || '3003', 10), | |
| apiKey: process.env.API_KEY || '', | |
| codeiumAuthToken: process.env.CODEIUM_AUTH_TOKEN || '', | |
| codeiumApiKey: process.env.CODEIUM_API_KEY || '', | |
| codeiumEmail: process.env.CODEIUM_EMAIL || '', | |
| codeiumPassword: process.env.CODEIUM_PASSWORD || '', | |
| codeiumApiUrl: process.env.CODEIUM_API_URL || 'https://server.self-serve.windsurf.com', | |
| defaultModel: process.env.DEFAULT_MODEL || 'claude-4.5-sonnet-thinking', | |
| maxTokens: parseInt(process.env.MAX_TOKENS || '8192', 10), | |
| logLevel: process.env.LOG_LEVEL || 'info', | |
| // Language server | |
| lsBinaryPath: process.env.LS_BINARY_PATH || '/opt/windsurf/language_server_linux_x64', | |
| lsPort: parseInt(process.env.LS_PORT || '42100', 10), | |
| // Dashboard | |
| dashboardPassword: process.env.DASHBOARD_PASSWORD || '', | |
| }; | |
| const levels = { debug: 0, info: 1, warn: 2, error: 3 }; | |
| const currentLevel = levels[config.logLevel] ?? 1; | |
| export const log = { | |
| debug: (...args) => currentLevel <= 0 && console.log('[DEBUG]', ...args), | |
| info: (...args) => currentLevel <= 1 && console.log('[INFO]', ...args), | |
| warn: (...args) => currentLevel <= 2 && console.warn('[WARN]', ...args), | |
| error: (...args) => currentLevel <= 3 && console.error('[ERROR]', ...args), | |
| }; | |