fixed webshare
This commit is contained in:
parent
9413d6588d
commit
b501d7a2da
5 changed files with 67 additions and 5 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { ConfigLoader } from '../types';
|
||||
import { ConfigLoaderError } from '../errors';
|
||||
import { readFileSync } from 'fs';
|
||||
|
||||
export interface EnvLoaderOptions {
|
||||
convertCase?: boolean;
|
||||
|
|
@ -26,6 +27,9 @@ export class EnvLoader implements ConfigLoader {
|
|||
|
||||
async load(): Promise<Record<string, unknown>> {
|
||||
try {
|
||||
// Load root .env file only
|
||||
this.loadEnvFile('../../.env'); // Root .env
|
||||
|
||||
const config: Record<string, unknown> = {};
|
||||
const envVars = process.env;
|
||||
|
||||
|
|
@ -137,4 +141,42 @@ export class EnvLoader implements ConfigLoader {
|
|||
// Return as string
|
||||
return value;
|
||||
}
|
||||
|
||||
private loadEnvFile(filePath: string): void {
|
||||
try {
|
||||
const envContent = readFileSync(filePath, 'utf-8');
|
||||
const lines = envContent.split('\n');
|
||||
|
||||
for (const line of lines) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed || trimmed.startsWith('#')) {
|
||||
continue; // Skip empty lines and comments
|
||||
}
|
||||
|
||||
const equalIndex = trimmed.indexOf('=');
|
||||
if (equalIndex === -1) {
|
||||
continue; // Skip lines without =
|
||||
}
|
||||
|
||||
const key = trimmed.substring(0, equalIndex).trim();
|
||||
let value = trimmed.substring(equalIndex + 1).trim();
|
||||
|
||||
// Remove surrounding quotes if present
|
||||
if ((value.startsWith('"') && value.endsWith('"')) ||
|
||||
(value.startsWith("'") && value.endsWith("'"))) {
|
||||
value = value.slice(1, -1);
|
||||
}
|
||||
|
||||
// Only set if not already set (allows override precedence)
|
||||
if (!(key in process.env)) {
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
// File not found is not an error (env files are optional)
|
||||
if (error.code !== 'ENOENT') {
|
||||
console.warn(`Warning: Could not load env file ${filePath}:`, error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue