Fork me on GitHub
#reitit
<
2022-03-06
>
sound2gd12:03:01

in reitit.coercison,malli, is there a way to convert a inst to long, not string.

manas_marthi15:03:35

How do I add CORS support for Reitit? Pls advise.

Oliver Marks19:03:51

@manas.marthi This will probably get you going

(defn allow-cross-origin
  ([handler]
   (allow-cross-origin handler "*"))
  ([handler allowed-origins]
   (fn [request]
     (if (= (:request-method request) :options)
       (-> {:status 200 :body ""}
           (assoc-in [:headers "Access-Control-Allow-Headers"] "*")
           (assoc-in [:headers "Access-Control-Allow-Origin"] allowed-origins)
           (assoc-in [:headers "Access-Control-Allow-Methods"] "HEAD,GET,POST,DELETE"))

       (-> (handler request)
           (assoc-in [:headers "Access-Control-Allow-Headers"] "*")
           (assoc-in [:headers "Access-Control-Allow-Origin"] allowed-origins)
           (assoc-in [:headers "Access-Control-Allow-Methods"] "HEAD,GET,POST,DELETE"))))))
Then just add it in the :middleware key and adjust as needed

1