framework-one/fw1-clj

Ensure composability of middleware

Closed this issue · 4 comments

It should be easy to add extra middleware to a FW/1 app. The framework defaults setup is probably the biggest obstacle. Depends on #2 being done first.

The easiest way might be to add an optional vector of middleware functions and run them in the wrapper function.

The existing middleware should be the default vector and you should be able to replace or append (with append being the default I think).

Hmm, append or prepend would be sensible options. We may want some middleware to be the first thing executed (so it can decide not to execute what it wraps). For example, RIng's wrap-resource really needs to be the first thing executed in a request and therefore the last function wrapped around other middleware.

So prepend should be the default, with [wrap-params wrap-flash wrap-session (wrap-resource (stem "/"))] being the normal base middleware to which additional stuff should be prepended.

Appending and replacing should be considered advanced actions so maybe I won't support those in the first cut of this?

You can now specify :middleware in the startup options as a vector of middleware to add. The first item can optionally be :append, :replace, or :prepend. If not specified, :prepend is assumed.