Hi folks, I am still using an old version of duct and I have a question. Say one of my components is referencing a composite key that is defined in one of the :include
but I want to override with a new implementation of init-key
How I would go about that?
One thing that I cannot do is to modify the original files, so it will have to go in a separate .edn
file...
Yeah I am on a version that does not have profiles...
You can pretty trivially rebuild profiles how you want them using duct/merge-configs
. Assuming your version of duct has it.
Just be sure to use the same set of readers.
I wouldn’t use merge
, as you’ll probably want the meta-merge
semantics.
Thank you sounds good
I was thinking of doing something like
(merge (io/resource "config.edn")
(io/resource "overrides.edn"))
forgot to mention that this is not as dev
profile but it will be read by a completely separate "production" app
We pass multiple profiles
to (duct/prep-config (read-config) profiles)
, so that later profiles overwrite keys in earlier ones. E.g. we pass [:duct.profile/dev :duct.profile/local]
for dev, so that anything in local.edn
overrides the defaults in dev.edn
.
Does anyone have a pro-tip for getting the raw request body in a duct application? I'm not able to do (slurp (:body request))
as it returns an empty string - I am assuming because it has been consumed by an earlier middleware
Add an earlier middleware that copies the request body to a separate key 🤷
How does one tinker with the middleware order in duct? Especially those that are included by default?
:duct.server.http/jetty
{:port #duct/env ["HTTP_SERVER_PORT" Int :or 5000]
:handler #ig/ref :<http://my-app.app/handler|my-app.app/handler>
:logger #ig/ref :duct.logger/timbre}
; ...
:<http://my-app.app/handler|my-app.app/handler>
{:router #ig/ref :duct.router/cascading
:middleware [#ig/ref :my-app.middleware/sentry
#ig/ref :my-app.middleware/bind-db
#ig/ref :my-app.middleware.session/bind-session
#ig/ref :duct.middleware.web/not-found
#ig/ref :duct.middleware.web/webjars
#ig/ref :duct.middleware.web/format
#ig/ref :duct.middleware.web/defaults
#ig/ref :duct.middleware.web/log-requests
#ig/ref :duct.middleware.web/log-errors
#ig/ref :my-app.middleware/error-middleware]}
I.e. overwrite your Jetty handler's :middleware
Thank you so much. This got me to the correct solution. I may be on a newer/older version - but it was enough to reorder only the relevant pieces:
:duct.handler/root
{:middleware [#ig/ref :web.middleware/cors
#ig/ref :duct.middleware.web/not-found
#ig/ref :duct.middleware.web/format
#ig/ref :duct.middleware.web/defaults
#ig/ref :web.middleware/raw-body]}
(instead of replacing the entire vector)
prep-config
shows all the defaults are still present, just reordered 🙂