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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?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');
});
/*
| 后台 Vue SPApublic/admin子路径需回退到 index.html否则刷新 /admin/venues 等会得到 404。
| 静态文件assets/*)若存在则直出;其余路径统一返回 index.html。
| index 使用字符串响应而非 BinaryFileResponse避免部分 Nginx + X-Sendfile 配置下返回 500。
*/
Route::get('/admin/{path?}', function (?string $path = null) {
$adminBase = realpath(public_path('admin'));
if ($adminBase === false || ! is_dir($adminBase)) {
abort(503, 'Admin frontend is not deployed (missing public/admin).');
}
if ($path !== null && $path !== '') {
$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)) {
return response()->file($candidate);
}
}
$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',
]);
})->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', '.*');