46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
// router.php - Front controller & router for PHP built-in server
|
|
|
|
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
|
|
|
// 1. Route API requests
|
|
if (strpos($uri, '/api/') === 0) {
|
|
require __DIR__ . '/api.php';
|
|
exit;
|
|
}
|
|
|
|
// 2. Serve static files if they exist
|
|
$filePath = __DIR__ . $uri;
|
|
if ($uri !== '/' && file_exists($filePath) && !is_dir($filePath)) {
|
|
$ext = pathinfo($filePath, PATHINFO_EXTENSION);
|
|
$mimes = [
|
|
'css' => 'text/css',
|
|
'js' => 'application/javascript',
|
|
'json' => 'application/json',
|
|
'png' => 'image/png',
|
|
'jpg' => 'image/jpeg',
|
|
'jpeg' => 'image/jpeg',
|
|
'gif' => 'image/gif',
|
|
'svg' => 'image/svg+xml',
|
|
'ico' => 'image/x-icon',
|
|
'woff' => 'font/woff',
|
|
'woff2'=> 'font/woff2',
|
|
'ttf' => 'font/ttf',
|
|
];
|
|
|
|
if (isset($mimes[$ext])) {
|
|
header('Content-Type: ' . $mimes[$ext]);
|
|
}
|
|
readfile($filePath);
|
|
exit;
|
|
}
|
|
|
|
// 3. Serve Frontend Application
|
|
if (file_exists(__DIR__ . '/static/index.html')) {
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
readfile(__DIR__ . '/static/index.html');
|
|
exit;
|
|
}
|
|
|
|
echo "سامانه مدیریت مسائل شهری شهرنگار فعال است.";
|