26 lines
781 B
PHP
26 lines
781 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once dirname(__DIR__, 3) . '/backend/Config.php';
|
|
require_once dirname(__DIR__, 3) . '/backend/Database.php';
|
|
|
|
function api_json(array $payload, int $status = 200): void
|
|
{
|
|
http_response_code($status);
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
header('Cache-Control: no-store');
|
|
header('X-Content-Type-Options: nosniff');
|
|
header('Referrer-Policy: no-referrer');
|
|
header('X-Frame-Options: DENY');
|
|
echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
exit;
|
|
}
|
|
|
|
function api_method(string $expected): void
|
|
{
|
|
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== $expected) {
|
|
header('Allow: ' . $expected);
|
|
api_json(['error' => 'method_not_allowed'], 405);
|
|
}
|
|
}
|