Fork me on GitHub
#pedestal
<
2023-06-19
>
hifumi12303:06:56

I’m trying to use the CORS interceptor that comes out of the box with Pedestal, but I can’t figure out what I’m doing wrong. I am using the following service map.

{::http/routes          routes
 ::http/type            :jetty
 ::http/port            8080
 ::http/join?           false
 ::http/allowed-origins [""]}
My route tree looks as follows:
(def routes
  (route/expand-routes #{["/hello" :get  hello :route-name :routes/get-hello]
                         ["/hello" :head hello :route-name :routes/head-hello]}))
Then when try sending OPTIONS /hello, I get a 404 response from the server.

souenzzo09:06:38

add this:

::http/allowed-origins {:allowed-origins (fn [origin]
                                           (let [allowed (contains? #{""} origin)]
                                             (log/info :origin origin :allowed allowed)
                                             allowed))}
Will help you to debug. maybe your allowed-origins is not working (aka no logs at all). this is because you are not using default-interceptors or something like maybe you are using the wrong origin name

hifumi12309:06:29

Your suggestion works, it looks like I misread the docstring or it’s become outdated

souenzzo10:06:25

the array form should be supported and equivalent to this map+function.

hifumi12310:06:54

Yeah, I just did some testing and it looks like everything works when I use ["localhost"] instead of my original example

hifumi12310:06:57

Thanks for the guidance