Fork me on GitHub
#beginners
<
2020-05-10
>
Michael Thurmond18:05:47

I have a reitit server and a reagent template and I'm trying to allow CORS. I've tried using wrap-cors from ring middleware but am having trouble getting it to work. Has anyone else experience this?

(def app2
  (ring/ring-handler
    (ring/router
      [["/" {:get {:handler index-handler}}]
       ["/items"
        ["" {:get {:handler index-handler}}]
        ["/:item-id" {:get {:handler    index-handler
                            :parameters {:path {:item-id int?}}}}]]
       ["/about" {:get {:handler index-handler}}]]
      {:data {:coercion   reitit.coercion.spec/coercion
              :muuntaja   m/instance
              :middleware [params/wrap-params
                           muuntaja/format-middleware
                           coercion/coerce-exceptions-middleware
                           coercion/coerce-request-middleware
                           coercion/coerce-response-middleware]}})
    (ring/create-default-handler)))

v21:05:38

Try calling the end points directly I.e ‘/items’, without the <localhost://portnumber/|localhost://portnumber/>

Michael Thurmond21:05:59

thanks, that didn't work because the frontend is on port 3449 and the backend is on 3000

dharrigan18:05:42

Perhaps #reitit would have more answers?

dvingo21:05:03

what's the idiomatic way to determine if a vector contains an element (i know contains? looks up the index, not the val) is it to: (contains? (set ['1 '2 '3]) '3) ?

seancorfield21:05:59

If it's an operation you need to perform repeatedly, I'd consider using a different data structure (than a vector). What's going to be idiomatic as a solution is going to depend on the problem you are trying to solve...?

👍 2
dvingo21:05:50

thanks - i guess my question is better phrased as what are ways to check that a vector contains a value?

phronmophobic22:05:31

(some #{42} my-vec) is a common way to test if my-vec contains the value 42

dvingo00:05:23

thank you!

krzyz06:05:19

Be careful not to check for false or nil that way. Be aware of the “long” version: (some #(= % false) my-vec)