webman迁移
This commit is contained in:
@@ -6,6 +6,48 @@
|
||||
*/
|
||||
|
||||
use Webman\Route;
|
||||
use support\Response;
|
||||
|
||||
// ==================== 未安装时根路径重定向(迁移自 public/index.php) ====================
|
||||
// 当 install.lock 不存在或未完成安装时,访问 / 或 /index.html 重定向到安装页
|
||||
$installLockFile = public_path('install.lock');
|
||||
$installCompleteMark = 'install-end';
|
||||
$installPageFile = public_path('install/index.html');
|
||||
Route::get('/', function () use ($installLockFile, $installCompleteMark, $installPageFile) {
|
||||
$needRedirect = is_file($installPageFile)
|
||||
&& (!is_file($installLockFile) || @file_get_contents($installLockFile) !== $installCompleteMark);
|
||||
if ($needRedirect) {
|
||||
return new Response(302, ['Location' => '/install/']);
|
||||
}
|
||||
if (is_file(public_path('index.html'))) {
|
||||
return new Response(302, ['Location' => '/index.html']);
|
||||
}
|
||||
return new Response(404, [], 'Not Found');
|
||||
});
|
||||
Route::get('/index.html', function () use ($installLockFile, $installCompleteMark, $installPageFile) {
|
||||
$needRedirect = is_file($installPageFile)
|
||||
&& (!is_file($installLockFile) || @file_get_contents($installLockFile) !== $installCompleteMark);
|
||||
if ($needRedirect) {
|
||||
return new Response(302, ['Location' => '/install/']);
|
||||
}
|
||||
$file = public_path('index.html');
|
||||
return is_file($file) ? (new Response())->file($file) : new Response(404, [], 'Not Found');
|
||||
});
|
||||
|
||||
// ==================== 安装向导(静态页) ====================
|
||||
// /install、/install/、/install/index 均返回 public/install/index.html
|
||||
Route::get('/install', function () {
|
||||
$file = public_path('install/index.html');
|
||||
return is_file($file) ? (new Response())->file($file) : new Response(404, [], 'Install page not found');
|
||||
});
|
||||
Route::get('/install/', function () {
|
||||
$file = public_path('install/index.html');
|
||||
return is_file($file) ? (new Response())->file($file) : new Response(404, [], 'Install page not found');
|
||||
});
|
||||
Route::get('/install/index', function () {
|
||||
$file = public_path('install/index.html');
|
||||
return is_file($file) ? (new Response())->file($file) : new Response(404, [], 'Install page not found');
|
||||
});
|
||||
|
||||
// ==================== API 路由 ====================
|
||||
|
||||
@@ -20,7 +62,7 @@ Route::post('/api/user/logout', [\app\api\controller\User::class, 'logout']);
|
||||
Route::add(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD'], '/api/install/terminal', [\app\api\controller\Install::class, 'terminal']);
|
||||
Route::post('/api/install/changePackageManager', [\app\api\controller\Install::class, 'changePackageManager']);
|
||||
Route::get('/api/install/envBaseCheck', [\app\api\controller\Install::class, 'envBaseCheck']);
|
||||
Route::get('/api/install/envNpmCheck', [\app\api\controller\Install::class, 'envNpmCheck']);
|
||||
Route::add(['GET', 'POST'], '/api/install/envNpmCheck', [\app\api\controller\Install::class, 'envNpmCheck']);
|
||||
Route::post('/api/install/testDatabase', [\app\api\controller\Install::class, 'testDatabase']);
|
||||
Route::add(['GET', 'POST'], '/api/install/baseConfig', [\app\api\controller\Install::class, 'baseConfig']);
|
||||
Route::post('/api/install/commandExecComplete', [\app\api\controller\Install::class, 'commandExecComplete']);
|
||||
@@ -190,4 +232,4 @@ Route::get('/admin/security/dataRecycleLog/info', [\app\admin\controller\securit
|
||||
// 放在最后注册;显式加上前端会请求的路径,再加固通配
|
||||
Route::add('OPTIONS', '/api/index/index', [\app\common\middleware\AllowCrossDomain::class, 'optionsResponse']);
|
||||
Route::add('OPTIONS', '/api/{path:.+}', [\app\common\middleware\AllowCrossDomain::class, 'optionsResponse']);
|
||||
Route::add('OPTIONS', '/admin/{path:.+}', [\app\common\middleware\AllowCrossDomain::class, 'optionsResponse']);
|
||||
Route::add('OPTIONS', '/admin/{path:.+}', [\app\common\middleware\AllowCrossDomain::class, 'optionsResponse']);
|
||||
Reference in New Issue
Block a user