优化 远程调用代码
This commit is contained in:
parent
1206b9c92f
commit
7cd2928e45
@ -19,9 +19,7 @@ public function index()
|
||||
|
||||
public function call(Request $request, Module $module)
|
||||
{
|
||||
$path = request()->path();
|
||||
$path = substr($path, strlen('/api/modules/' . $module->id));
|
||||
$path = preg_replace('/[^a-zA-Z0-9\/]/', '', $path);
|
||||
$path = $this->fixPath($request, $module, 'api');
|
||||
|
||||
$method = Str::lower($request->method());
|
||||
|
||||
@ -45,11 +43,7 @@ public function call(Request $request, Module $module)
|
||||
|
||||
public function exportCall(Request $request, Module $module): Response|JsonResponse
|
||||
{
|
||||
$path = request()->path();
|
||||
|
||||
$path = substr($path, strlen('/modules/modules/' . $module->id));
|
||||
$path = preg_replace('/[^a-zA-Z0-9\/]/', '', $path);
|
||||
|
||||
$path = $this->fixPath($request, $module, 'modules');
|
||||
$method = Str::lower($request->method());
|
||||
|
||||
$response = $module->moduleRequest($method, $path, $request->all());
|
||||
@ -60,4 +54,10 @@ public function exportCall(Request $request, Module $module): Response|JsonRespo
|
||||
|
||||
return $this->moduleResponse($response['json'], $response['status']);
|
||||
}
|
||||
|
||||
private function fixPath(Request $request, Module $module, $prefix): string
|
||||
{
|
||||
$path = substr($request->path(), strlen("/{$prefix}/modules/{$module->id}"));
|
||||
return preg_replace('/[^a-zA-Z0-9\/]/', '', $path);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user