| 199 | |
| 200 | // Load worker .env file for OpenSearch and other worker-specific variables |
| 201 | function loadWorkerEnv() { |
| 202 | const envPath = path.join(__dirname, 'worker', '.env'); |
| 203 | const env = {}; |
| 204 | |
| 205 | try { |
| 206 | if (fs.existsSync(envPath)) { |
| 207 | const envContent = fs.readFileSync(envPath, 'utf-8'); |
| 208 | envContent.split('\n').forEach((line) => { |
| 209 | const trimmed = line.trim(); |
| 210 | // Skip comments and empty lines |
| 211 | if (!trimmed || trimmed.startsWith('#')) { |
| 212 | return; |
| 213 | } |
| 214 | const match = trimmed.match(/^([^=]+)=(.*)$/); |
| 215 | if (match) { |
| 216 | const key = match[1].trim(); |
| 217 | let value = match[2].trim(); |
| 218 | // Remove surrounding quotes if present |
| 219 | if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) { |
| 220 | value = value.slice(1, -1); |
| 221 | } |
| 222 | env[key] = value; |
| 223 | } |
| 224 | }); |
| 225 | } |
| 226 | } catch (err) { |
| 227 | console.warn('Failed to load worker .env file:', err.message); |
| 228 | } |
| 229 | |
| 230 | return env; |
| 231 | } |
| 232 | |
| 233 | const workerEnv = loadWorkerEnv(); |
| 234 | |