'image/jpeg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', 'gif' => 'image/gif', 'webp' => 'image/webp', 'svg' => 'image/svg+xml', 'css' => 'text/css', 'js' => 'application/javascript', 'json' => 'application/json', 'ico' => 'image/x-icon', ]; header('Content-Type: ' . ($mimeTypes[$ext] ?? 'application/octet-stream')); header('Content-Length: ' . filesize($filePath)); header('Cache-Control: public, max-age=31536000'); readfile($filePath); exit; } // API 请求走后端入口 if (str_starts_with($uri, '/api/')) { require_once __DIR__ . '/public/index.php'; exit; } // 非 API 请求返回前端 SPA 入口(index.html),前端 Vue Router 负责渲染路由 $indexHtml = __DIR__ . '/public/index.html'; if (file_exists($indexHtml)) { header('Content-Type: text/html; charset=utf-8'); readfile($indexHtml); exit; } // 兜底:无法处理 http_response_code(404); echo 'Not Found'; exit;