Skip to content

Middleware compilers don't get access to route path #720

@valerauko

Description

@valerauko

:compile'ing middleware takes a bit of effort around the internals if the compiler function would need the route path.

In my case, I have a logger middleware that would include the route path template (also available as :template in Match) in the log. This information is fixed at compile time, so it feels wasteful to extract it every request from the Match.

Workaround

Using a :compile like below (in the case of reitit.ring/router) injects the :path into the data passed into the compiler.

(defn compile-add-path
  [[path data extra] opts]
  (reitit.ring/compile-result [path (assoc data :path path) extra] opts))

Path is a special case because it's treated separately from the data. Documentation around :compile isn't that rich, so I think it'd be preferable to inject the path into route-data (rather than have people copy-paste a compiler function they don't understand)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions