<?php
declare(strict_types=1);
if (!defined('STORE_ROOT')) { http_response_code(403); exit; }
function renderHandler(string $action, array $in): void {
if ($action !== 'page') { App::err('Unknown action for render'); }
$page = $in['page'] ?? null;
if (!$page) { App::err('No page specified.'); }
if (!in_array($page, PUBLIC_PAGES, true)) { App::err('Page not found or access denied.', 404); }
$file = dirname(__DIR__, 2) . '/pages/' . $page . '.php';
if (!file_exists($file)) { App::err('Page not found.', 404); }
App::rateLimitDB('router', 120, 60);
ob_start();
include $file;
$html = ob_get_clean();
$newCsrf = Auth::regenerateCsrf();
echo json_encode(['html' => $html, 'csrf' => $newCsrf, 'page' => $page]);
exit;
}
