You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.2 KiB

3 days ago
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
3 days ago
/*
3 days ago
| 后台 Vue SPApublic/admin子路径需回退到 index.html否则刷新 /admin/venues 等会得到 404。
| 静态文件assets/*)若存在则直出;其余路径统一返回 index.html。
| index 使用字符串响应而非 BinaryFileResponse避免部分 Nginx + X-Sendfile 配置下返回 500。
3 days ago
*/
Route::get('/admin/{path?}', function (?string $path = null) {
3 days ago
$adminBase = realpath(public_path('admin'));
if ($adminBase === false || ! is_dir($adminBase)) {
abort(503, 'Admin frontend is not deployed (missing public/admin).');
}
3 days ago
if ($path !== null && $path !== '') {
3 days ago
$relative = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path);
$candidate = realpath($adminBase.DIRECTORY_SEPARATOR.$relative);
if ($candidate !== false
&& str_starts_with($candidate, $adminBase)
&& is_file($candidate)
&& is_readable($candidate)) {
3 days ago
return response()->file($candidate);
}
}
3 days ago
$index = $adminBase.DIRECTORY_SEPARATOR.'index.html';
if (! is_file($index) || ! is_readable($index)) {
abort(503, 'Admin index.html is missing or unreadable.');
}
$html = @file_get_contents($index);
if ($html === false) {
abort(503, 'Cannot read admin index.html.');
}
return response($html, 200, [
'Content-Type' => 'text/html; charset=UTF-8',
]);
3 days ago
})->where('path', '.*');
2 days ago
/*
| 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', '.*');