duct-framework / module.web

Duct module for running web applications
21 stars 20 forks source link

Removing a middleware #14

Closed g7s closed 5 years ago

g7s commented 5 years ago

Instead of the default ring stacktrace middleware in the development environment I wanted to user this one https://github.com/magnars/prone but I cannot find a way to "replace" the :duct.web.middleware/stacktrace key in the :middlewares of the root handler. Is there any clean way that we can do this?

Thanks

weavejester commented 5 years ago

The most straightforward way is to replace the :middlewares key with the explicit list of middleware you want.

I've been considering alternative designs that would make it easier to replace default middleware, but currently it can only be done by explicitly choosing the middleware, or by writing a module.

g7s commented 5 years ago

That's fine. I ended up getting what middleware are in use in the dev environment

dev> (-> config :duct.handler/root :middleware)

and replaced the middleware explicitly. Worked fine! Thank you

g7s commented 4 years ago

Here is an idea.

:my/alias #ig/override :the/actual-implementation

so that would be overridable only when the :my/alias key is present?

:my/alias {,,,}

Does it make sense?

weavejester commented 4 years ago

I don't think that's something I'd want to add to Integrant, but I'm also not entirely sure how it helps in this case. Can you explain?

g7s commented 4 years ago

Yes ofc. The idea is to be able to override the implementation of a key that exists in a place where that cannot be done "cleanly". For example take the use case of this issue. I know that :duct.web.middleware/stacktrace's implementation is a middleware that is used by the duct.module-web that I want to override with another implementation. I could say that

:my.project.middleware/stacktrace #ig/overrides :duct.web.middleware/stacktrace

in my main.edn. Then in my (say) dev profile I could have

:my.project.middleware/stacktrace {}

where its implementation will be a middleware.

If we have merge-configs be aware of the overrides and replace any reference to :duct.web.middleware/stacktrace with a reference to :my.project.middleware/stacktrace (provided that at least one profile implements :my.project.middleware/stacktrace) wouldn't that work? I don't know if any of this makes sense with the current state of things in Integrant.

weavejester commented 4 years ago

I think it might be better to have a way of removing keys or even nested values when merging. I don't think an override tag is a good fit for Integrant.

g7s commented 4 years ago

Fair point. Having a way to remove or replace nested keys / values when merging sounds a better thing to have.