代码之家  ›  专栏  ›  技术社区  ›  Freid001

如何将COR添加到compojure api应用程序?

  •  3
  • Freid001  · 技术社区  · 6 年前

    (def app
        (api
            {:swagger {:ui   "/docs"
                       :spec "/swagger.json"}}
    
           (GET "/route-a" [] "a")
           (GET "/route-b" [] "b")
           (GET "/route-c" [] "c")))
    

    我想用 https://github.com/r0man/ring-cors

    (-> (api
       {:swagger {:ui   "/docs"
                  :spec "/swagger.json"}}
    
       (GET "/route-a" [] "a")
       (GET "/route-b" [] "b")
       (GET "/route-c" [] "c"))
    
      (wrap-cors :access-control-allow-origin #"http://localhost:81"
                 :access-control-allow-headers ["Origin" "X-Requested-With"
                                            "Content-Type" "Accept"]
                 :access-control-allow-methods [:get :put :post :delete :options]))
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   Aleph Aleph    6 年前

    仅当请求具有 Origin 与指定正则表达式匹配的头(当使用 XMLHttpRequest 在浏览器中,原点标头将自动添加)。

    curl -vH "Origin: http://localhost:81" localhost:3000/route-a
    

    http://localhost:81 也应该有用。