<?php
ini_set('short_open_tag', '1');
// este es el index.php
//declare(strict_types=1);


$allowed_origins = [
    'http://localhost:5010',
    'http://localhost:6010','http://localhost:6011',
    'http://localhost:6510',
    'https://smart.idxmulti.com',
    'https://smartback.idxmulti.com',
    'https://newpol-back.idxmulti.com',
    'https://newpol-front.idxmulti.com',
];

$origin = $_SERVER['HTTP_ORIGIN'] ?? '';

if (in_array($origin, $allowed_origins)) {
    header("Access-Control-Allow-Origin: $origin");
}

header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");

if (!isset($_SERVER['HTTP_AUTHORIZATION'])) {
    $headers = getallheaders();
    if (isset($headers['Authorization'])) {
        $_SERVER['HTTP_AUTHORIZATION'] = $headers['Authorization'];
    }
}

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

error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
error_reporting(E_ALL & ~E_NOTICE);


//echo 'upload_tmp_dir: ' . ini_get('upload_tmp_dir') . PHP_EOL;echo 'sys_get_temp_dir(): ' . sys_get_temp_dir();die("xxxx");
//if( isset$_GET['debug']){ phpinfo();die("x");}
// Cargar phpseclib manualmente
require __DIR__ . '/vendor/autoload.php';

// Ahora puedes usar phpseclib sin composer
use phpseclib3\Net\SFTP;
 


ini_set('display_errors', 0);

set_time_limit(6000); // 6000 segundos = 100 minutos
// Configuración de la zona horaria
if (function_exists('date_default_timezone_set')) {
    date_default_timezone_set('America/Mexico_City');
} else {
    ini_set('date.timezone', 'America/Mexico_City');
}   
date_default_timezone_set('America/Mexico_City');



// Manejar preflight OPTIONS (importante!)
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
    http_response_code(200);
    exit;
}




//require 'vendor/autoload.php';

require_once 'utils/Logger.php';
require_once 'flight/Flight.php';

require_once __DIR__ . '/klaas_auto.php';
// require 'flight/autoload.php';

$entorno = getenv('APP_ENV') ?: 'default';
//echo "Entorno cargado: $entorno";



require_once __DIR__ . '/routes.php';
