Project

General

Profile

Actions

Feature #101996

open

Static routes should be able to call custom PHP Implementations

Added by Philipp Wrann 8 months ago. Updated 4 months ago.

Status:
New
Priority:
Should have
Assignee:
Category:
Link Handling, Site Handling & Routing
Start date:
2023-09-21
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Complexity:
Sprint Focus:

Description

Just like you can configure a custom errorHandler it should be possible to register a custom route handler. At the moment you would always have to call another page, that is configured in a way it returns the desired response. But if you want to provide a custom sitemap index or a dynamically generated robots.txt it would be much more intuitive if i could configure the static route with a custom php request handler.


Files

Actions #1

Updated by Stefan Bürk 8 months ago

  • Category changed from Frontend to Link Handling, Site Handling & Routing
  • Assignee set to Stefan Bürk

configure the static route with a custom php request handler.

That means, you want to write some kind of request handler in
a php class in your extension, and than configure it. Right ?

I would not introduce another request layer here. Instead of
creating a handler and configure it you could simply implement
a PSR-15 Middleware and handle it after the core SiteResolver
middleware and before the static route middleware.

A middleware is such a handler and everything is in please.
Instead of configure it in the static route configuration
you have to check the route in the request in the middleware.

Maybe you can add more context to it why an additional layer
would be of any benifit.

Actions #2

Updated by Philipp Wrann 8 months ago

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.

Actions #3

Updated by Lina Wolf 4 months ago

I agree with Philipp Wrann, We do have such a handler for the errorpages and it would make sense to have them for the static routes as well.

A common problem in the robots.txt is the sitemap. The sitemap must be defined with an absolute URL in the robots.txt, so a common use case is that you would want to use the url of the current site configuration here.

Additionally it is currently not possible to have the robots.txt for a site within the sitepackage. It is not possible to link to an EXT: Link currently, you will get

Static files are usefull (and a pain in the neck) beyond robots.txt. For example browsers and search engines still like to look at example.com/favicon.ico for the favicon. In Multisite installations I would like to define that path in the site configuration and have the favicon in the extension for example. (Yes I can also do that with a middleware)

Actions

Also available in: Atom PDF