duct

kelveden 2019-09-12T14:18:35.069400Z

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.

kelveden 2019-09-12T14:20:11.069700Z

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

kelveden 2019-09-12T14:32:04.070Z

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)

kelveden 2019-09-12T14:32:28.070200Z

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

teaforthecat 2019-09-12T16:44:40.070400Z

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

teaforthecat 2019-09-12T16:58:41.070600Z

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.

kelveden 2019-09-12T17:53:47.070800Z

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

kelveden 2019-09-12T18:09:43.071Z

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!

👍 1
bocaj 2019-09-12T23:40:04.071900Z

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
?