serveSpa('index.html'); } private function serveSpa(string $file) { $path = rtrim(public_path($file), '/\\'); if (!is_file($path)) { return response('前端尚未编译,请在项目根目录执行 npm run build', 503, [ 'Content-Type' => 'text/plain; charset=utf-8', ]); } return response(file_get_contents($path), 200, [ 'Content-Type' => 'text/html; charset=utf-8', ]); } }