Files

63 lines
1.8 KiB
PHP

<?php
/**
* Built-in PHP Router for Forex Trading Journal
*/
$uri = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
// API Router
if (strpos($uri, '/api/') === 0 || $uri === '/api') {
require __DIR__ . '/api.php';
exit;
}
// Uploaded Images
if (strpos($uri, '/uploads/') === 0) {
$filePath = __DIR__ . $uri;
if (file_exists($filePath) && is_file($filePath)) {
$ext = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
$mimes = [
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'png' => 'image/png',
'webp' => 'image/webp',
'gif' => 'image/gif'
];
$mime = $mimes[$ext] ?? 'application/octet-stream';
header('Content-Type: ' . $mime);
readfile($filePath);
exit;
}
http_response_code(404);
echo "File not found";
exit;
}
// Static Files
$staticFile = __DIR__ . '/static' . $uri;
if (file_exists($staticFile) && is_file($staticFile)) {
$ext = strtolower(pathinfo($staticFile, PATHINFO_EXTENSION));
$mimes = [
'css' => 'text/css; charset=utf-8',
'js' => 'application/javascript; charset=utf-8',
'json' => 'application/json; charset=utf-8',
'png' => 'image/png',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'svg' => 'image/svg+xml',
'ico' => 'image/x-icon',
'woff' => 'font/woff',
'woff2'=> 'font/woff2',
'ttf' => 'font/ttf',
'html' => 'text/html; charset=utf-8'
];
$mime = $mimes[$ext] ?? 'text/plain; charset=utf-8';
header('Content-Type: ' . $mime);
readfile($staticFile);
exit;
}
// Default Single Page Application Entry
header('Content-Type: text/html; charset=utf-8');
readfile(__DIR__ . '/static/index.html');