@@ -46,6 +46,13 @@ class Router
4646 */
4747 protected array $ group_middlewares = [];
4848
49+ /**
50+ * Allowed HTTP methods
51+ *
52+ * @var array<int, string>
53+ */
54+ protected array $ allowed_methods = ['GET ' , 'POST ' , 'PUT ' , 'PATCH ' , 'DELETE ' , 'HEAD ' , 'OPTIONS ' ];
55+
4956 /**
5057 * Gets mapped routes.
5158 *
@@ -74,7 +81,19 @@ public function clear(): void
7481 */
7582 public function map (string $ pattern , callable $ callback , bool $ pass_route = false , string $ route_alias = '' ): Route
7683 {
77- $ url = trim ($ pattern );
84+
85+ // This means that the route ies defined in a group, but the defined route is the base
86+ // url path. Note the '' in route()
87+ // Ex: Flight::group('/api', function() {
88+ // Flight::route('', function() {});
89+ // }
90+ // Keep the space so that it can execute the below code normally
91+ if ($ this ->group_prefix !== '' ) {
92+ $ url = ltrim ($ pattern );
93+ } else {
94+ $ url = trim ($ pattern );
95+ }
96+
7897 $ methods = ['* ' ];
7998
8099 if (false !== strpos ($ url , ' ' )) {
@@ -83,7 +102,12 @@ public function map(string $pattern, callable $callback, bool $pass_route = fals
83102 $ methods = explode ('| ' , $ method );
84103 }
85104
86- $ route = new Route ($ this ->group_prefix . $ url , $ callback , $ methods , $ pass_route , $ route_alias );
105+ // And this finishes it off.
106+ if ($ this ->group_prefix !== '' ) {
107+ $ url = rtrim ($ this ->group_prefix . $ url );
108+ }
109+
110+ $ route = new Route ($ url , $ callback , $ methods , $ pass_route , $ route_alias );
87111
88112 // to handle group middleware
89113 foreach ($ this ->group_middlewares as $ gm ) {
0 commit comments