Files
davidson-ci/scripts/static-router.php
T
pauljd 3068f739e4
pauljd/davidson-ci: Davidson CI / ai-review (push) Successful in 1m0s
pauljd/davidson-ci: Davidson CI / quality (push) Successful in 1m18s
Improve CI reporting and Lighthouse checks
2026-10-01 12:01:57 +01:00

23 lines
734 B
PHP

<?php
declare(strict_types=1);
// Router for the Lighthouse static server.
// PHP's built-in server answers requests for missing files with index.html,
// which makes Lighthouse read HTML as robots.txt. Return a real 404 instead.
$path = rawurldecode((string) parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH));
$root = (string) realpath($_SERVER['DOCUMENT_ROOT'] ?? '.');
$target = realpath($root . $path);
$insideRoot = $target !== false
&& ($target === $root || str_starts_with($target, $root . DIRECTORY_SEPARATOR));
if ($insideRoot && (is_file($target) || is_file($target . '/index.html'))) {
return false;
}
http_response_code(404);
header('Content-Type: text/plain; charset=utf-8');
echo "404 Not Found\n";