Add static file serving from content directory

Only serve non-PHP/HTML/MD files as static assets Check mime type and
serve with appropriate content type
This commit is contained in:
Ruben 2025-10-02 23:40:51 +02:00
parent 45cfc6e1b7
commit 0a1bc74fa6

View file

@ -359,6 +359,18 @@ if (file_exists($assetPath) && is_file($assetPath)) {
exit; exit;
} }
// Check for static files in content directory
$contentFilePath = rtrim($contentDir, '/') . '/' . ltrim($requestPath, '/');
if (file_exists($contentFilePath) && is_file($contentFilePath)) {
$ext = pathinfo($contentFilePath, PATHINFO_EXTENSION);
// Only serve non-PHP/non-HTML/non-MD files as static assets
if (!in_array($ext, ['php', 'html', 'md'])) {
header('Content-Type: ' . (mime_content_type($contentFilePath) ?: 'application/octet-stream'));
readfile($contentFilePath);
exit;
}
}
// Handle frontpage // Handle frontpage
if (empty($requestPath)) { if (empty($requestPath)) {
// Try language-specific frontpage first, then default // Try language-specific frontpage first, then default