Fork me on GitHub
#duct
<
2021-04-13
>
richiardiandrea00:04:10

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...

richiardiandrea00:04:57

I was thinking of doing something like

(merge (io/resource "config.edn")
       (io/resource "overrides.edn"))

richiardiandrea00:04:19

forgot to mention that this is not as dev profile but it will be read by a completely separate "production" app

walterl01:04:21

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.

richiardiandrea15:04:40

Yeah I am on a version that does not have profiles...

rickmoynihan07:04:31

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.

rickmoynihan07:04:58

I wouldn’t use merge, as you’ll probably want the meta-merge semantics.

👍 4
richiardiandrea15:04:50

Thank you sounds good

scaturr14:04:48

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

walterl15:04:14

Add an earlier middleware that copies the request body to a separate key 🤷

scaturr15:04:03

How does one tinker with the middleware order in duct? Especially those that are included by default?

walterl17:04:19

:duct.server.http/jetty
  {:port    #duct/env ["HTTP_SERVER_PORT" Int :or 5000]
   :handler #ig/ref :
   :logger  #ig/ref :duct.logger/timbre}

; ...

  :
  {: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]}

walterl17:04:47

I.e. overwrite your Jetty handler's :middleware

scaturr20:04:47

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]}

🎉 2
scaturr20:04:22

(instead of replacing the entire vector)

scaturr20:04:46

prep-config shows all the defaults are still present, just reordered 🙂