Files
2026-02-17 09:29:34 -06:00

39 lines
795 B
PHP

<?php
declare(strict_types=1);
use function Lasuca\SharedEndpoint\fetchLatestItems;
require_once __DIR__ . '/../src/Database.php';
$config = include __DIR__ . '/../config.php';
try {
$items = fetchLatestItems($config['mysql']);
} catch (Throwable $throwable) {
http_response_code(500);
header('Content-Type: application/json');
echo json_encode(
[
'status' => 'error',
'message' => $throwable->getMessage(),
]
);
exit;
}
$metadata = [
'generatedAt' => gmdate(DATE_ATOM),
'count' => count($items),
];
$payload = [
'status' => 'ok',
'metadata' => $metadata,
'items' => $items,
];
header('Content-Type: application/json');
header('Cache-Control: max-age=1');
echo json_encode($payload, JSON_PRETTY_PRINT);