Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions Classes/Extbase/RouteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ public function __construct(RouteService $service, Bootstrap $bootstrap, Respons
$this->bootstrap = $bootstrap;
$this->routeService = $service;
}

/**
* Returns the Path of the requested URI without the site base path.
*
* @param ServerRequestInterface $request
* @return string
*/
private function slugFromRequest(ServerRequestInterface $request): string {
$slug = $request->getUri()->getPath();

// Remove the site base path from the slug - see: typo3/sysext/frontend/Classes/Middleware/StaticRouteResolver.php
if (($site = $request->getAttribute('site', null)) instanceof \TYPO3\CMS\Core\Site\Entity\Site) {
$siteBasePath = '/' . trim($site->getBase()->getPath(), '/');
if(str_starts_with($slug, $siteBasePath)) {
$slug = substr($slug, strlen($siteBasePath));
$slug = '/' . ltrim($slug, '/');
}
}
return $slug;
}

/**
* @throws NoConfigurationException
Expand All @@ -75,7 +95,7 @@ public function __construct(RouteService $service, Bootstrap $bootstrap, Respons
*/
public function handle(ServerRequestInterface $request)
{
$slug = $request->getUri()->getPath();
$slug = $this->slugFromRequest($request);

try {
$this->processRoute($request, $this->routeService->findRouteFor($slug));
Expand Down Expand Up @@ -130,7 +150,7 @@ private function processMiddleware(ServerRequestInterface $request): void
return;
}

$slug = $request->getUri()->getPath();
$slug = $this->slugFromRequest($request);

foreach ($this->routeService->findMiddlewareFor($slug) as $middlewareRoute) {
$middleware = GeneralUtility::makeInstance(Middleware::class);
Expand Down
3 changes: 2 additions & 1 deletion Classes/Routing/RestApiEnhancer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function enhanceForMatching(RouteCollection $collection): void
{
$defaultOptions = $collection->get('default')->getOptions();

$apiRoute = new Route('/api/{any}', [], ['any' => '.*'], $defaultOptions);
$pathPrefix = empty($this->configuration['pathPrefix']) ? '/api/' : ('/' . trim($this->configuration['pathPrefix'], '/') . '/');
$apiRoute = new Route($pathPrefix . '{any}', [], ['any' => '.*'], $defaultOptions);

$collection->add('api', $apiRoute);
}
Expand Down