pandeiro / boot-http

A simple HTTP serve task for the Boot build tool
62 stars 34 forks source link

how can I don CORS? #48

Open sjatkins opened 8 years ago

sjatkins commented 8 years ago

I don't see an option here to do it although I do see one for ring servers. I would prefer to not use ring (mainly out of laziness and too much else to do). My situation is that I have a local http server at another point that I would like to access from clojurescript.

I am starting boot-http server like (server :reload true) so I am taking the defaults.

arichiardi commented 8 years ago

Yes I would be interested in having an option for this too..in particular I see that boot-http is already including ring handlers so maybe a simple patch would be to add the one that does CORS here?

arichiardi commented 8 years ago

@sjatkins can you post the link to the ring handler? Here is the link: https://github.com/r0man/ring-cors

An alternative would of course to be a custom handler as :handler option

Naomarik commented 8 years ago

@sjatkins Quickest solution without adding any deps is to throw this somewhere and use it in the handler option.

(:require
   [pandeiro.boot-http.impl :refer [dir-handler]]))

(defn asset-handler [req]
  (-> req
      ((dir-handler {:dir "assets"}))
      (assoc-in [:headers "Access-Control-Allow-Origin"] "*")))