45 lines
1.4 KiB
PHP
45 lines
1.4 KiB
PHP
![]() |
<?php
|
||
|
// Serve static files from /app directory
|
||
|
$file = $_GET['file'] ?? '';
|
||
|
$file = str_replace(['../', '..\\'], '', $file); // Prevent directory traversal
|
||
|
|
||
|
// Map request paths to actual file paths
|
||
|
$basePath = __DIR__ . '/';
|
||
|
$customBasePath = dirname(__DIR__) . '/';
|
||
|
|
||
|
if (str_starts_with($file, 'styles/')) {
|
||
|
$filePath = $customBasePath . 'custom/' . $file;
|
||
|
} elseif (str_starts_with($file, 'fonts/')) {
|
||
|
$filePath = $customBasePath . 'custom/' . $file;
|
||
|
} elseif (str_starts_with($file, 'default-styles/')) {
|
||
|
$filePath = $basePath . 'default/' . substr($file, 15); // Remove 'default-styles/' prefix
|
||
|
} elseif (str_starts_with($file, 'docs-styles/')) {
|
||
|
$filePath = $basePath . 'default/docs/styles/' . substr($file, 12); // Remove 'docs-styles/' prefix
|
||
|
} else {
|
||
|
http_response_code(404);
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
// Check if file exists and is readable
|
||
|
if (!file_exists($filePath) || !is_readable($filePath)) {
|
||
|
http_response_code(404);
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
// Determine MIME type based on extension
|
||
|
$ext = pathinfo($filePath, PATHINFO_EXTENSION);
|
||
|
$mimeTypes = [
|
||
|
'css' => 'text/css',
|
||
|
'js' => 'application/javascript',
|
||
|
'woff' => 'font/woff',
|
||
|
'woff2' => 'font/woff2',
|
||
|
'ttf' => 'font/ttf',
|
||
|
'otf' => 'font/otf',
|
||
|
'eot' => 'application/vnd.ms-fontobject',
|
||
|
'svg' => 'image/svg+xml',
|
||
|
];
|
||
|
|
||
|
$mimeType = $mimeTypes[$ext] ?? (mime_content_type($filePath) ?: 'application/octet-stream');
|
||
|
header('Content-Type: ' . $mimeType);
|
||
|
readfile($filePath);
|