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.It's probably not really relevant but the ring middleware I'm using is: https://github.com/r0man/ring-cors
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)
It feels like it should be applied before the routing even happens.
I have a :handlers
key next to :routes
and :middleware
, maybe try that?
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.Thanks @teaforthecat I'll take a look when I'm in front of my code later.
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!
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
?