2022-08-19 19:48:37 +08:00
|
|
|
<?php
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | swiftAdmin 极速开发框架 [基于 WebMan 开发]
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | Copyright (c) 2022-2030 http://www.swiftadmin.net
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | swiftAdmin.net High Speed Development Framework
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
use Webman\Route;
|
|
|
|
|
|
2022-11-28 19:11:12 +08:00
|
|
|
// 验证码路由
|
|
|
|
|
Route::any('/captcha', [app\BaseController::class, 'captcha']);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 加载自定义路由 [插件路由]
|
|
|
|
|
*/
|
2022-08-19 19:48:37 +08:00
|
|
|
$defineRoute = require __DIR__ . '/defineRoute.php';
|
|
|
|
|
if ($defineRoute && is_array($defineRoute)) {
|
|
|
|
|
foreach ($defineRoute as $key => $value) {
|
|
|
|
|
Route::any($key, $value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-28 19:11:12 +08:00
|
|
|
/**
|
|
|
|
|
* 默认管理员路由
|
|
|
|
|
* @var string $manage
|
|
|
|
|
*/
|
2022-08-19 19:48:37 +08:00
|
|
|
Route::any('/manage', function () {
|
2022-08-22 23:04:57 +08:00
|
|
|
request()->session()->set('AdminLogin', ['_security' => request()->buildToken()]);
|
2022-08-22 19:07:32 +08:00
|
|
|
return redirect('/admin/login');
|
2022-08-19 19:48:37 +08:00
|
|
|
});
|
|
|
|
|
|
2022-11-28 19:11:12 +08:00
|
|
|
/**
|
|
|
|
|
* 加载插件全局初始化路由
|
|
|
|
|
* @var array $pluginRoute
|
|
|
|
|
*/
|
|
|
|
|
Route::any('/static/system/js/plugin.js', function () {
|
|
|
|
|
$plugins = get_plugin_list();
|
|
|
|
|
$pluginFiles = [];
|
|
|
|
|
foreach ($plugins as $item) {
|
|
|
|
|
if (!$item['status']) {
|
2022-08-19 19:48:37 +08:00
|
|
|
continue;
|
|
|
|
|
}
|
2022-11-28 19:11:12 +08:00
|
|
|
// 是否存在javascript文件
|
|
|
|
|
$pluginJs = plugin_path($item['name']) . 'plugin.js';
|
|
|
|
|
if (file_exists($pluginJs)) {
|
|
|
|
|
$pluginFiles[] = read_file($pluginJs);
|
2022-08-19 19:48:37 +08:00
|
|
|
}
|
|
|
|
|
}
|
2022-11-28 19:11:12 +08:00
|
|
|
return $pluginFiles ? implode(PHP_EOL, $pluginFiles) : '';
|
|
|
|
|
});
|
2022-08-19 19:48:37 +08:00
|
|
|
|
2022-11-28 19:11:12 +08:00
|
|
|
/**
|
|
|
|
|
* 全局404路由fallback
|
|
|
|
|
* @var array $request
|
|
|
|
|
* @var array $response
|
|
|
|
|
*/
|
2022-08-19 19:48:37 +08:00
|
|
|
Route::fallback(function ($request) {
|
2023-04-25 20:11:49 +08:00
|
|
|
|
2022-08-19 19:48:37 +08:00
|
|
|
$pathInfo = parse_url(request()->url());
|
|
|
|
|
if (!isset($pathInfo['path'])) {
|
|
|
|
|
$parseApp = ['index'];
|
2023-04-25 20:11:49 +08:00
|
|
|
} elseif ($pathInfo['path'] == '/') {
|
|
|
|
|
// 默认应用路由
|
|
|
|
|
return redirect('/index');
|
2022-08-19 19:48:37 +08:00
|
|
|
} else {
|
|
|
|
|
$parseApp = explode('/', ltrim($pathInfo['path'], '/'));
|
|
|
|
|
}
|
2023-04-25 20:11:49 +08:00
|
|
|
|
|
|
|
|
// 判断是否为API接口
|
2022-08-19 19:48:37 +08:00
|
|
|
if ($request->expectsJson()) {
|
|
|
|
|
return json(['code' => 404, 'msg' => '404 not found']);
|
|
|
|
|
}
|
2023-04-25 20:11:49 +08:00
|
|
|
|
2022-08-19 19:48:37 +08:00
|
|
|
return response(request_error(current($parseApp)), 404);
|
|
|
|
|
});
|