Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Midlleware registred on individual routes #7

@umputun

Description

@umputun

Currently, each handler is wrapped individually with middleware, offering a relatively simple implementation. However, this approach has a limitation: it doesn't allow the registration of middleware that acts on both registered and unregistered routes. While this might not pose a problem in most cases, there are situations where we might want a general middleware, such as for logging, to act on all routes.

A more appropriate solution would be to apply middleware at the group level rather than on each individual route. However, all the solutions I have explored so far have been complex and introduced a significant amount of non-intuitive code.

An alternative solution is to implement a "catch-all" handler for not-found cases on the root ("/") path, but only if no other root path has already been registered. Although this approach may seem unconventional, it offers a straightforward implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions