pedestal

lucian303 2020-06-19T19:33:37.244900Z

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?

2020-06-19T19:40:47.246600Z

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

lucian303 2020-06-19T19:43:19.247Z

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

lucian303 2020-06-19T19:48:14.247500Z

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

2020-06-19T20:01:21.248800Z

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

2020-06-19T20:01:29.249200Z

so the * won't work here

lucian303 2020-06-19T20:03:50.249600Z

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

2020-06-19T20:03:54.249800Z

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

2020-06-19T20:04:09.250200Z

that should effectively be the same as "*"

lucian303 2020-06-19T20:06:53.250600Z

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')",

2020-06-19T20:12:42.251200Z

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

lucian303 2020-06-19T20:21:25.251700Z

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

lucian303 2020-06-19T20:21:38.252100Z

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