diff --git a/Libs/Utils/RequestUtils.php b/Libs/Utils/RequestUtils.php index ccb735a6..247ad43a 100644 --- a/Libs/Utils/RequestUtils.php +++ b/Libs/Utils/RequestUtils.php @@ -1,20 +1,18 @@ uri(); + public static function getCurrentRoutePath($request) + { + try + { + $route = Route::getRoutes()->match($request); + if(is_null($route)) return false; + $route_path = $route->uri(); if (strpos($route_path, '/') != 0) $route_path = '/' . $route_path; return $route_path; - } - catch (\Exception $ex) - { - Log::error($ex); - } - return false; - } + } + catch (\Exception $ex) + { + Log::error($ex); + } + return false; + } } \ No newline at end of file diff --git a/app/Http/Middleware/CORSMiddleware.php b/app/Http/Middleware/CORSMiddleware.php index 5582dc85..3e36dd5a 100644 --- a/app/Http/Middleware/CORSMiddleware.php +++ b/app/Http/Middleware/CORSMiddleware.php @@ -157,7 +157,7 @@ class CORSMiddleware $real_method = $request->headers->get('Access-Control-Request-Method'); $request->setMethod($real_method); - $route_path = RequestUtils::getCurrentRoutePath(); + $route_path = RequestUtils::getCurrentRoutePath($request); if (!$route_path || !$this->checkEndPoint($route_path, $real_method)) { $response = new Response(); diff --git a/app/Http/Middleware/OAuth2BearerAccessTokenRequestValidator.php b/app/Http/Middleware/OAuth2BearerAccessTokenRequestValidator.php index 29539d03..26615fdd 100644 --- a/app/Http/Middleware/OAuth2BearerAccessTokenRequestValidator.php +++ b/app/Http/Middleware/OAuth2BearerAccessTokenRequestValidator.php @@ -86,7 +86,7 @@ class OAuth2BearerAccessTokenRequestValidator try { - $route = RequestUtils::getCurrentRoutePath(); + $route = RequestUtils::getCurrentRoutePath($request); if (!$route) { throw new OAuth2ResourceServerException( 400, diff --git a/app/Http/Middleware/RateLimitMiddleware.php b/app/Http/Middleware/RateLimitMiddleware.php index 31e98b2c..92cebcab 100644 --- a/app/Http/Middleware/RateLimitMiddleware.php +++ b/app/Http/Middleware/RateLimitMiddleware.php @@ -62,7 +62,7 @@ final class RateLimitMiddleware extends ThrottleRequests */ public function handle($request, Closure $next, $max_attempts = 0, $decay_minutes = 0) { - $route = RequestUtils::getCurrentRoutePath(); + $route = RequestUtils::getCurrentRoutePath($request); $method = $request->getMethod(); $endpoint = $this->endpoint_repository->getApiEndpointByUrlAndMethod($route, $method); $key = $this->resolveRequestSignature($request);