Files
miles c250653961 Add comprehensive test suite for application functionality
- Implement tests for HTTP API endpoints, ensuring correct responses and security headers.
- Create configuration tests to validate loading of defaults and environment overrides.
- Add tests for FEDL service to verify data handling and snapshot functionality.
- Introduce GitHub service tests to check API data normalization and caching behavior.
- Develop monitor service tests for network checks and uptime calculations.
- Implement persistence tests to ensure database migrations are idempotent and data persists across restarts.
- Add vault service tests for session management and brute-force protection mechanisms.
- Include helper functions for test context creation and JSON response handling.
2026-11-08 16:24:06 -06:00

41 lines
1.1 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
/**
* Minimal .env loader. No dependency, no variable expansion.
* Existing process env values always win.
*/
export function loadEnv(file = path.resolve(process.cwd(), '.env')) {
let text;
try {
text = fs.readFileSync(file, 'utf8');
} catch {
return {};
}
const loaded = {};
for (const rawLine of text.split(/\r?\n/)) {
const line = rawLine.trim();
if (!line || line.startsWith('#')) continue;
const eq = line.indexOf('=');
if (eq === -1) continue;
let key = line.slice(0, eq).trim();
if (key.startsWith('export ')) key = key.slice(7).trim();
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) continue;
let value = line.slice(eq + 1).trim();
if (
(value.startsWith('"') && value.endsWith('"')) ||
(value.startsWith("'") && value.endsWith("'"))
) {
value = value.slice(1, -1);
}
// Basic escape support for double-quoted values.
value = value.replace(/\\n/g, '\n').replace(/\\r/g, '\r');
if (process.env[key] === undefined) {
process.env[key] = value;
loaded[key] = value;
}
}
return loaded;
}