/**
* Configuration module for Postiz Media Manager
* Loads settings from environment variables
*/
import dotenv from 'dotenv';
// Load environment variables from .env file
dotenv.config();
/**
* Application configuration
*/
export interface Config {
/** Base URL for Postiz API (e.g., https://api.postiz.app or self-hosted URL) */
postizBaseUrl: string;
/** API token for authentication (Bearer token) */
postizApiToken: string;
/** Log level for debugging */
logLevel: 'debug' | 'info' | 'warn' | 'error';
}
/**
* Validates and returns configuration from environment variables
* @throws Error if required configuration is missing
*/
export function getConfig(): Config {
const postizBaseUrl = process.env.POSTIZ_BASE_URL;
const postizApiToken = process.env.POSTIZ_API_TOKEN;
const logLevel = (process.env.LOG_LEVEL || 'info') as Config['logLevel'];
if (!postizBaseUrl) {
throw new Error('POSTIZ_BASE_URL environment variable is required');
}
if (!postizApiToken) {
throw new Error('POSTIZ_API_TOKEN environment variable is required');
}
// Remove trailing slash from base URL
const normalizedBaseUrl = postizBaseUrl.replace(/\/$/, '');
return {
postizBaseUrl: normalizedBaseUrl,
postizApiToken,
logLevel,
};
}
/**
* Global config instance
*/
export const config = getConfig();