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.

56 lines
1.9 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', '.*');