Skip to content

Commit

Permalink
fixed: api-server root middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
chaz6chez committed Jul 12, 2024
1 parent f4cdc8b commit 72b8632
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/ApiRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
class ApiRoute implements Bootstrap
{
const TAG_GROUP = '#group';
const TAG_ROOT = '#root';

/**
* @var RouteCollector|null
Expand Down Expand Up @@ -221,7 +222,13 @@ public static function route(array|string $httpMethod, string $route, Closure $h
'handler' => $handler
];
}
self::middleware(self::getMiddlewareTag($handler), self::$_groupPrefix !== null ? self::getMiddlewares('#group') : $middlewares, $methods);
self::middleware(
self::getMiddlewareTag($handler),
self::getMiddlewares(self::TAG_ROOT) + (self::$_groupPrefix !== null ?
self::getMiddlewares(self::TAG_GROUP) :
$middlewares),
$methods
);
self::$_collector->addRoute($methods, $route, $handler);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ApiServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function onWorkerStart(Worker $worker): void
}
}
if ($mid) {
ApiRoute::middleware(ApiRoute::TAG_GROUP, $mid);
ApiRoute::middleware(ApiRoute::TAG_ROOT, $mid);
}
}
}
Expand Down

0 comments on commit 72b8632

Please sign in to comment.