Fork me on GitHub
#pedestal
<
2020-06-19
>
lucian30319:06:37

i'm trying to add cors headers through the pedestal config. i set ::http/allowed-origins ["*"] but the header i get back is blank: Access-Control-Allow-Origin: and there is no Access-Control-Allow-Methods: header. even if i force "*" for that header, it still gets stripped out. is this something i need a custom interceptor for?

dvingo19:06:47

your usage sounds correct to me - I would just double check what the final service config looks like when you start the server. Maybe try copying your service config to a new app template and see if that works also

lucian30319:06:19

minus the routes, it looks like this:

{:env :prod,
 :io.pedestal.http/not-found-interceptor {:name :neo.common.http.passthrough/passthrough,
                                          :leave #object[neo.common.http.passthrough$fn__36795
                                                         0x6ba197f9
                                                         "neo.common.http.passthrough$fn__36795@6ba197f9"]},
 :io.pedestal.http/routes #{...},
 :io.pedestal.http/allowed-origins ["*"],
 :io.pedestal.http/type :jetty,
 :io.pedestal.http/container-options {:h2c? true, :h2? false, :ssl? false},
 :io.pedestal.http/host "0.0.0.0",
 :io.pedestal.http/port 8080}
i will try it in a new template

lucian30319:06:14

in the template, i get no cors headers at all w/ that setting on or off

dvingo20:06:21

interesting I'm seeing the headers not show up as well with '*'. digging into the implementation it looks like the origin check is using set membership: https://github.com/pedestal/pedestal/blob/master/service/src/io/pedestal/http/cors.clj#L57

dvingo20:06:29

so the * won't work here

lucian30320:06:50

i c. good to know. i opened up a ticket for this https://github.com/pedestal/pedestal/issues/664

dvingo20:06:54

::http/allowed-origins {:creds true :allowed-origins (constantly true)}})

dvingo20:06:09

that should effectively be the same as "*"

lucian30320:06:53

that gives me an error unfortunately: #error{:cause "class java.lang.Long cannot be cast to class clojure.lang.IPersistentCollection (java.lang.Long is in module java.base of loader 'bootstrap'; clojure.lang.IPersistentCollection is in unnamed module of loader 'app')",

dvingo20:06:42

seems like that is caused by something else. Here's a full example: https://github.com/pedestal/pedestal/blob/master/samples/cors/src/cors/server.clj#L27

lucian30320:06:25

i'm getting the error running normally also, so it's not just the run-dev

lucian30320:06:38

unfortunately, removing that line from my run dev ends up w/ everything responding w/ a 403