Browse Source

better basePath support

Maurits van der Schee 5 years ago
parent
commit
9dde583166
2 changed files with 23 additions and 12 deletions
  1. 11
    5
      api.php
  2. 12
    7
      src/Tqdev/PhpCrudApi/Middleware/Router/SimpleRouter.php

+ 11
- 5
api.php View File

@@ -4809,14 +4809,20 @@ class SimpleRouter implements Router
4809 4809
         if ($basePath) {
4810 4810
             return $basePath;
4811 4811
         }
4812
-        if (isset($_SERVER['PATH_INFO'])) {
4812
+        if (isset($_SERVER['REQUEST_URI'])) {
4813 4813
             $fullPath = explode('?', $_SERVER['REQUEST_URI'])[0];
4814
-            $path = $_SERVER['PATH_INFO'];
4815
-            if (substr($fullPath, -1 * strlen($path)) == $path) {
4816
-                return substr($fullPath, 0, -1 * strlen($path));
4814
+            if (isset($_SERVER['PATH_INFO'])) {
4815
+                $path = $_SERVER['PATH_INFO'];
4816
+                if (!$path) {
4817
+                    return $_SERVER['PHP_SELF'];
4818
+                }
4819
+                if (substr($fullPath, -1 * strlen($path)) == $path) {
4820
+                    return substr($fullPath, 0, -1 * strlen($path));
4821
+                }
4817 4822
             }
4823
+            return $fullPath;
4818 4824
         }
4819
-        return $_SERVER['PHP_SELF'];
4825
+        return '/';
4820 4826
     }
4821 4827
 
4822 4828
     private function loadPathTree(): PathTree

+ 12
- 7
src/Tqdev/PhpCrudApi/Middleware/Router/SimpleRouter.php View File

@@ -41,15 +41,20 @@ class SimpleRouter implements Router
41 41
         if ($basePath) {
42 42
             return $basePath;
43 43
         }
44
-        $fullPath = explode('?', $_SERVER['REQUEST_URI'])[0];
45
-        $path = $_SERVER['PATH_INFO'];
46
-        if (!$path) {
44
+        if (isset($_SERVER['REQUEST_URI'])) {
45
+            $fullPath = explode('?', $_SERVER['REQUEST_URI'])[0];
46
+            if (isset($_SERVER['PATH_INFO'])) {
47
+                $path = $_SERVER['PATH_INFO'];
48
+                if (!$path) {
49
+                    return $_SERVER['PHP_SELF'];
50
+                }
51
+                if (substr($fullPath, -1 * strlen($path)) == $path) {
52
+                    return substr($fullPath, 0, -1 * strlen($path));
53
+                }
54
+            }
47 55
             return $fullPath;
48 56
         }
49
-        if (substr($fullPath, -1 * strlen($path)) == $path) {
50
-            return substr($fullPath, 0, -1 * strlen($path));
51
-        }
52
-        return $_SERVER['PHP_SELF'];
57
+        return '/';
53 58
     }
54 59
 
55 60
     private function loadPathTree(): PathTree

Loading…
Cancel
Save