当对我的 api 端点有错误请求时, wrap-cors不会返回访问控制标头。我相信这是因为我使用的异常处理程序可能会阻止中间件运行。我想知道我如何仍然可以执行此路由的中间件并将 cors 标头附加到错误请求的响应中。
异常处理程序
(defn- bad-request-handler
"Handles bad requests."
[f]
(f
(ring/response {:status "bad request"})))
应用程序
(def app
(api
{:exceptions {:handlers
{::ex/request-validation (bad-request-handler response/bad-request)}}}
(POST "/" [] :body [item {(schema/required-key :item) schema/Bool}]
:middleware [#(wrap-cors % :access-control-allow-origin [#".*"]
:access-control-allow-methods [:post])]
:responses {200 {:description "ok"}
400 {:description "bad request"}} item)))