Make it possibility to overwrite the prefix *api* and do not ignore the site base path #25
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
Problem 1
Routing slugs are treated as absolute paths and not relative to the site configuration URL.
Consider the following example
* base URL in the TYPO3 site config: http://localhost:7080/rest
* path of a route in ext/Configuration/Routes.yml: api/v1/login
Requesting just http://localhost:7080/api/v1/login will not work since TYPO3 would not be able to find the site configuration (
TYPO3\CMS\Frontend\Middleware\SiteResolver).On the other hand requesting http://localhost:7080/rest/api/v1/login will lead to the problem that
LMS\Routes\Extbase\RouteHandlerwill not be able to match the route, since it tries to match the entire requested path (rest/api/v1/login) and not only the path below the site base path (rest), which would only be (api/v1/login).Problem 2
The prefix api of the route path is hardcoded in
LMS\Routes\Routing\RestApiEnhancer. Therefore, all routes in any Routes.yml that does not start with api/ will never work.Improvements in this Patch
This patch adds the possibility to overwrite the prefix api of the route path in
LMS\Routes\Routing\RestApiEnhancerwith the routeEnhancers configuration pathPrefix. This, makes it possible to configure routes in a Routes.yml, that do not need to beginn with api/.Furthermore, the site base path is taken into account wen matching routes in the
LMS\Routes\Extbase\RouteHandler. This makes it possible to use this extension on sites that does not have an empty site base path in the TYPO3 site config (e.g. http://localhost:7080/rest)Possible sample configuration: