Actually i do solve these issues with custom middlewares at the moment. But it feels a bit clumsy - like a hack - to do so. Always the hazzle with the position (after this and after this but before this and before that - works in that installation but not in another because some cms module is missing...)
Some situations, i found myself in:
- Add a route to dynamically generate some json feed, css file, etc.
- Add a route to provide an api to read cms data.
- Add a route to render a storybook for all available content types.
possible solutions¶
Using custom page types
Works but does not feel correct. I personally use custom typeNums to load partial HTML (basic ajax stuff) for example but not for arbitrary data endpoints.
custom middleware
Yes, you can do basically anything with a psr-15 middleware but i think the PSR-15 concept exists more for a generic request/response handling, so adding/removing/changing attributes on the messages themselves.
A proposal¶
By being able to configure additional routes for the frontend (that are not bound to a page), there would be a very stable api to do such things. There could also be a possibility of adding routeEnhancers for those static routes.
routes:
simpleExample:
route: simple
type: PHPRequestHandler
requestHandler: Vendor\Package\Controller\SomeController->dispatch
complexExample:
route: complex
type: PHPRequestHandler
requestHandler: Vendor\Package\Controller\SomeController->dispatch
routeEnhancers:
ListByTag:
routePath: '/{tag}'
_arguments:
tag: tagId
aspects:
tag:
type: PersistedAliasMapper
tableName: tags
routeFieldName: uid
This proposal makes the whole issue really complex but as i said some kind of "offical" api for such stuff would be awesome.