39 lines
1.0 KiB
PHP
39 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
$uriPath = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
|
|
$root = __DIR__;
|
|
|
|
if (str_starts_with($uriPath, '/backend/')) {
|
|
return false;
|
|
}
|
|
|
|
$frontendPath = $uriPath === '/' ? '/index.html' : $uriPath;
|
|
$file = realpath($root . '/frontend' . $frontendPath);
|
|
$frontendRoot = realpath($root . '/frontend');
|
|
|
|
if (
|
|
$file !== false
|
|
&& $frontendRoot !== false
|
|
&& str_starts_with($file, $frontendRoot)
|
|
&& is_file($file)
|
|
) {
|
|
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
|
|
$contentTypes = [
|
|
'css' => 'text/css; charset=utf-8',
|
|
'html' => 'text/html; charset=utf-8',
|
|
'js' => 'text/javascript; charset=utf-8',
|
|
'json' => 'application/json; charset=utf-8',
|
|
'svg' => 'image/svg+xml',
|
|
];
|
|
|
|
header('Content-Type: ' . ($contentTypes[$extension] ?? 'application/octet-stream'));
|
|
readfile($file);
|
|
return true;
|
|
}
|
|
|
|
http_response_code(404);
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
echo "Not found\n";
|