master
lion 2 days ago
parent 952c2c4009
commit 28faf7cc5a

@ -53,3 +53,39 @@ Route::get('/admin/{path?}', function (?string $path = null) {
'Content-Type' => 'text/html; charset=UTF-8',
]);
})->where('path', '.*');
/*
| H5 uni-apppublic/h5与 admin 相同,在「所有请求经 index.php」的环境下直出 assets、static 等静态资源,
| 否则 /h5/assets/*.js、/h5/static/tab/*.png 可能 404动态 import 与子路径资源会整页白屏。
*/
Route::get('/h5/{path?}', function (?string $path = null) {
$h5Base = realpath(public_path('h5'));
if ($h5Base === false || ! is_dir($h5Base)) {
abort(503, 'H5 frontend is not deployed (missing public/h5).');
}
if ($path !== null && $path !== '') {
$relative = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path);
$candidate = realpath($h5Base.DIRECTORY_SEPARATOR.$relative);
if ($candidate !== false
&& str_starts_with($candidate, $h5Base)
&& is_file($candidate)
&& is_readable($candidate)) {
return response()->file($candidate);
}
}
$index = $h5Base.DIRECTORY_SEPARATOR.'index.html';
if (! is_file($index) || ! is_readable($index)) {
abort(503, 'H5 index.html is missing or unreadable.');
}
$html = @file_get_contents($index);
if ($html === false) {
abort(503, 'Cannot read H5 index.html.');
}
return response($html, 200, [
'Content-Type' => 'text/html; charset=UTF-8',
]);
})->where('path', '.*');

Loading…
Cancel
Save