Fork me on GitHub
#duct
<
2019-09-12
>
kelveden14:09:35

I'm trying to add CORS ring middleware into my duct app (routing using ataraxy). My duct config looks something like this:

{:duct.core/project-ns     my
 :duct.router/ataraxy      {:routes     ^:cors
                                        {:options       [:my.handler/empty-handler]
                                         [:get "/ping"] [:my.handler/ping]}
                            :middleware {:cors #ig/ref :my.middleware.cors/cors}}
 :my.handler/empty-handler {}
 :my.handler/ping          {}}
My question is: how do I avoid needing that empty-handler for the pre-flight request? i.e. how do I apply the answer to this issue using duct? https://github.com/weavejester/ataraxy/issues/19.

kelveden14:09:11

It's probably not really relevant but the ring middleware I'm using is: https://github.com/r0man/ring-cors

kelveden14:09:04

I can't help but feel that I'm missing a trick here. Should the cors middleware be applied at a higher level than where I have it on the routes? It is also having the side effect that my route handlers have to return vanilla ring response maps (instead of ataraxy response vectors)

kelveden14:09:28

It feels like it should be applied before the routing even happens.

teaforthecat16:09:40

I have a :handlers key next to :routes and :middleware, maybe try that?

teaforthecat16:09:41

or try this:

:duct.handler/root
  {:router #ig/ref :duct.router/ataraxy
   :middleware [ #ig/ref :vocal.middleware/cors]}
That was probably what I meant in that issue. Sorry I’m just looking at this quickly and I haven’t been in that project in a while.

kelveden17:09:47

Thanks @U1UEABW4W I'll take a look when I'm in front of my code later.

kelveden18:09:43

That snippet above did the trick. I did try tinkering with duct.hander/root before but I must have not get it quite right. Thanks again!

👍 4
bocaj23:09:04

Not sure how to ask with out sharing each of my components, but where might this crop up from

Execution error (ClassCastException) at duct.core/fold-modules$fn (core.clj:145).
duct.database.sql.Boundary cannot be cast to clojure.lang.IFn
?