🧼 Clean up request handling by treating basePath similar to other routes

This commit is contained in:
Splashsky 2021-07-16 07:20:58 -05:00
parent 3dd5ddc83e
commit 227e5edc06

View File

@ -188,7 +188,7 @@ class Router
*/ */
public static function run(string $basePath = '', bool $multimatch = false) public static function run(string $basePath = '', bool $multimatch = false)
{ {
$basePath = rtrim($basePath, '/'); $basePath = self::trimRoute($basePath);
$method = $_SERVER['REQUEST_METHOD']; $method = $_SERVER['REQUEST_METHOD'];
$uri = parse_url($_SERVER['REQUEST_URI'])['path']; $uri = parse_url($_SERVER['REQUEST_URI'])['path'];
$path = urldecode(self::trimRoute($uri)); $path = urldecode(self::trimRoute($uri));
@ -198,7 +198,8 @@ class Router
// Begin looking through routes // Begin looking through routes
foreach (self::$routes as $route) { foreach (self::$routes as $route) {
if ($basePath != '' && $basePath != '/') { // If the basePath isn't just "root"
if ($basePath != '/') {
$route['route'] = $basePath.$route['route']; $route['route'] = $basePath.$route['route'];
} }