modulePath($module); if ($modulePath === null) { http_response_code(404); exit('Module not found.'); } $assetPath = realpath($modulePath . '/' . ltrim($path, '/')); $allowedRoot = realpath($modulePath); if ($assetPath === false || $allowedRoot === false || !str_starts_with($assetPath, $allowedRoot . DIRECTORY_SEPARATOR) || !is_file($assetPath)) { http_response_code(404); exit('Asset not found.'); } $extension = strtolower(pathinfo($assetPath, PATHINFO_EXTENSION)); $contentType = match ($extension) { 'css' => 'text/css; charset=utf-8', 'js' => 'application/javascript; charset=utf-8', 'json' => 'application/json; charset=utf-8', 'svg' => 'image/svg+xml', 'png' => 'image/png', 'jpg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'webp' => 'image/webp', default => 'application/octet-stream', }; $mtime = filemtime($assetPath); if ($mtime !== false) { header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $mtime) . ' GMT'); } header('Content-Type: ' . $contentType); header('Cache-Control: public, max-age=300'); readfile($assetPath);