mirror of
https://github.com/Dokploy/cli.git
synced 2026-06-16 04:35:23 +02:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user