Skip to content

Commit

Permalink
fix: 修复更新后导致节点后端交互api不可用的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xboard committed Apr 12, 2024
1 parent 7eb8d76 commit c2b08c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
5 changes: 3 additions & 2 deletions app/Http/Middleware/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Server
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next, $node_type = null)
{
// alias
$aliasTypes = [
Expand All @@ -27,6 +27,7 @@ public function handle(Request $request, Closure $next)
'token' => ['required', 'string', 'in:' . admin_setting('server_token')],
'node_id' => 'required',
'node_type' => [
'nullable',
'regex:/^(?i)(hysteria|hysteria2|vless|trojan|vmess|v2ray|tuic|shadowsocks|shadowsocks-plugin)$/',
function ($attribute, $value, $fail) use ($aliasTypes, $request) {
$request->merge([$attribute => strtolower(isset ($aliasTypes[$value]) ? $aliasTypes[$value] : $value)]);
Expand All @@ -36,7 +37,7 @@ function ($attribute, $value, $fail) use ($aliasTypes, $request) {
'token.in' => 'Token is error!',
'node_type.regex' => 'node_type is error!'
]);
$nodeInfo = ServerService::getServer($request->input('node_id'), $request->input('node_type'));
$nodeInfo = ServerService::getServer($request->input('node_id'), $request->input('node_type') ?? $node_type);
if (!$nodeInfo)
throw new ApiException('server is not exist!');
$request->merge(['node_info' => $nodeInfo]);
Expand Down
21 changes: 16 additions & 5 deletions app/Http/Routes/V1/ServerRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,35 @@ public function map(Registrar $router)
{
$router->group([
'prefix' => 'server',
'middleware' => 'server'
], function ($router) {
$router->prefix('UniProxy')->group(function ($route) {
$router->group([
'prefix' => 'UniProxy',
'middleware' => 'server'
] ,function ($route) {
$route->get('config', [UniProxyController::class, 'config']);
$route->get('user', [UniProxyController::class, 'user']);
$route->post('push', [UniProxyController::class, 'push']);
$route->post('alive', [UniProxyController::class, 'alive']);
});
$router->prefix('Deepbwork')->group(function ($route) {
$router->group([
'prefix' => 'Deepbwork',
'middleware' => 'server:vmess'
], function ($route) {
$route->get('config', [DeepbworkController::class, 'config']);
$route->get('user', [DeepbworkController::class, 'user']);
$route->post('submit', [DeepbworkController::class, 'submit']);
});
$router->prefix('ShadowsocksTidalab')->group(function ($route) {
$router->group([
'prefix' => 'ShadowsocksTidalab',
'middleware' => 'server:shadowsocks'
], function ($route) {
$route->get('user', [ShadowsocksTidalabController::class, 'user']);
$route->post('submit', [ShadowsocksTidalabController::class, 'submit']);
});
$router->prefix('TrojanTidalab')->group(function ($route) {
$router->group([
'prefix' => 'TrojanTidalab',
'middleware' => 'server:trojan'
], function ($route) {
$route->get('config', [TrojanTidalabController::class, 'config']);
$route->get('user', [TrojanTidalabController::class, 'user']);
$route->post('submit', [TrojanTidalabController::class, 'submit']);
Expand Down

0 comments on commit c2b08c2

Please sign in to comment.