<?php
declare(strict_types=1);

/**
 * Global App Settings & Headers
 */

// Set CORS
// Dynamically allow the requesting origin to support IP-based access and localhost
$allowedOrigin = $_SERVER['HTTP_ORIGIN'] ?? '*';
header("Access-Control-Allow-Origin: " . ($allowedOrigin !== '*' ? $allowedOrigin : '*'));
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With, X-Tenant-ID, Accept, Origin");
header("Access-Control-Allow-Credentials: true");

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    http_response_code(204);
    exit;
}

define('APP_VERSION', '1.0.0');
define('APP_ENV', $_SERVER['APP_ENV'] ?? getenv('APP_ENV') ?: 'production');
define('APP_URL', rtrim($_SERVER['APP_URL'] ?? getenv('APP_URL') ?: 'https://api.lomcos.com/billing/api', '/'));
define('FRONTEND_URL', rtrim($_SERVER['FRONTEND_URL'] ?? getenv('FRONTEND_URL') ?: 'https://app.lomcos.com/app', '/'));
define('UPLOAD_DIR', __DIR__ . '/../../app/uploads/');
