28 lines
640 B
PHP
28 lines
640 B
PHP
<?php
|
|
|
|
namespace app\controller;
|
|
|
|
use app\BaseController;
|
|
|
|
class Index extends BaseController
|
|
{
|
|
public function index()
|
|
{
|
|
return $this->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',
|
|
]);
|
|
}
|
|
}
|