handler file $routes = [ 'questionnaires' => __DIR__ . '/../handlers/questionnaires.php', 'questions' => __DIR__ . '/../handlers/questions.php', 'answer_options' => __DIR__ . '/../handlers/answer_options.php', 'translations' => __DIR__ . '/../handlers/translations.php', 'users' => __DIR__ . '/../handlers/users.php', 'assignments' => __DIR__ . '/../handlers/assignments.php', 'clients' => __DIR__ . '/../handlers/clients.php', 'clients/export' => __DIR__ . '/../handlers/client_export.php', 'clients/export_all' => __DIR__ . '/../handlers/client_export.php', 'activity' => __DIR__ . '/../handlers/activity.php', 'results' => __DIR__ . '/../handlers/results.php', 'export' => __DIR__ . '/../handlers/export.php', 'app_questionnaires' => __DIR__ . '/../handlers/app_questionnaires.php', 'logout' => __DIR__ . '/../handlers/logout.php', 'auth/login' => __DIR__ . '/../handlers/auth.php', 'auth/change-password' => __DIR__ . '/../handlers/auth.php', 'backup' => __DIR__ . '/../handlers/backup.php', 'download' => __DIR__ . '/../handlers/download.php', ]; try { if (!isset($routes[$route])) { json_error('NOT_FOUND', "Unknown endpoint: $route", 404); } $handlerFile = $routes[$route]; if (!file_exists($handlerFile)) { json_error('NOT_FOUND', "Handler not found for: $route", 404); } require $handlerFile; } catch (Throwable $e) { error_log("Unhandled error on $method $route: " . $e->getMessage()); json_error('SERVER_ERROR', 'Internal server error', 500); }