'Página no encontrada']); } http_response_code(200); header('Content-Type: text/html; charset=utf-8'); readfile($file); exit; } // ─── Router ────────────────────────────────────────────────────────────────── $method = $_SERVER['REQUEST_METHOD']; $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); // Normalizar: quitar trailing slash $path = rtrim($path, '/') ?: '/'; // ─── Tabla de rutas ────────────────────────────────────────────────────────── $routes = [ ['GET', '/health', fn() => jsonResponse(200, ['status' => 'ok', 'service' => 'bot-palmas360'])], // ─── WhatsApp webhook ──────────────────────────────────────────────────── // Seguridad: HMAC-SHA256 (X-Hub-Signature-256) verificado dentro del controlador ['GET', '/admin/v1/wp-webhook', fn() => WpWebhook::verify()], ['POST', '/admin/v1/wp-webhook', fn() => WpWebhook::receive()], // ─── Login / Logout ────────────────────────────────────────────────────── ['GET', '/login', fn() => LoginController::showForm()], ['POST', '/login', fn() => LoginController::authenticate()], ['GET', '/logout', fn() => LoginController::logout()], // ─── Dashboard protegido ───────────────────────────────────────────────── ['GET', '/admin/dashboard', fn() => DashboardController::index()], ['GET', '/admin/live', fn() => DashboardController::live()], ['GET', '/admin/webhook/stream', fn() => DashboardController::stream()], ['GET', '/admin/webhook/raw', fn() => DashboardController::getRaw()], // ─── Páginas legales (requeridas por Meta/WhatsApp Business) ──────────── ['GET', '/politicas', fn() => serveHtml('politicas.html')], ['GET', '/eliminacion-datos-usuario', fn() => serveHtml('eliminacion-datos-usuario.html')], ['GET', '/condiciones-servicio', fn() => serveHtml('condiciones-servicio.html')], ]; // ─── Despacho ──────────────────────────────────────────────────────────────── foreach ($routes as [$routeMethod, $routePath, $handler]) { if ($method === $routeMethod && $path === $routePath) { $handler(); exit; } } jsonResponse(404, ['error' => 'Ruta no encontrada', 'path' => $path]);