feat: add environment configuration support

- Introduced .env.example file to provide a template for environment variables.
- Updated .gitignore to exclude .env files from version control.
- Implemented loadEnvFile function in client.ts to load environment variables from a .env file into process.env, enhancing configuration management.
This commit is contained in:
Mauricio Siu
2026-04-15 18:42:13 -06:00
parent 70f542990d
commit 4d604a1a75
3 changed files with 23 additions and 2 deletions

View File

@@ -13,7 +13,27 @@ export interface AuthConfig {
url: string;
}
function loadEnvFile(): void {
const envPath = path.resolve(process.cwd(), ".env");
if (!fs.existsSync(envPath)) return;
const content = fs.readFileSync(envPath, "utf8");
for (const line of content.split("\n")) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith("#")) continue;
const eqIndex = trimmed.indexOf("=");
if (eqIndex === -1) continue;
const key = trimmed.slice(0, eqIndex).trim();
const value = trimmed.slice(eqIndex + 1).trim().replace(/^["']|["']$/g, "");
if (!process.env[key]) {
process.env[key] = value;
}
}
}
export function readAuthConfig(): AuthConfig {
loadEnvFile();
const envToken =
process.env.DOKPLOY_API_KEY ?? process.env.DOKPLOY_AUTH_TOKEN;
const envUrl = process.env.DOKPLOY_URL;