mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +00:00
Merge pull request #286 from metosin/fix-285
Check also pedestal interceptor key values, fixes #285
This commit is contained in:
commit
c2d362dcd1
3 changed files with 27 additions and 6 deletions
|
|
@ -6,6 +6,7 @@
|
|||
[reitit.swagger :as swagger]
|
||||
[reitit.swagger-ui :as swagger-ui]
|
||||
[reitit.http.coercion :as coercion]
|
||||
[reitit.dev.pretty :as pretty]
|
||||
[reitit.http.interceptors.parameters :as parameters]
|
||||
[reitit.http.interceptors.muuntaja :as muuntaja]
|
||||
[reitit.http.interceptors.exception :as exception]
|
||||
|
|
@ -126,12 +127,12 @@
|
|||
{:default-src "'self'"
|
||||
:style-src "'self' 'unsafe-inline'"
|
||||
:script-src "'self' 'unsafe-inline'"}}}
|
||||
(io.pedestal.http/default-interceptors)
|
||||
(server/default-interceptors)
|
||||
;; use the reitit router
|
||||
(pedestal/replace-last-interceptor router)
|
||||
(io.pedestal.http/dev-interceptors)
|
||||
(io.pedestal.http/create-server)
|
||||
(io.pedestal.http/start))
|
||||
(server/dev-interceptors)
|
||||
(server/create-server)
|
||||
(server/start))
|
||||
(println "server running in port 3000"))
|
||||
|
||||
(comment
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
(cond
|
||||
(interceptor/interceptor? interceptor)
|
||||
interceptor
|
||||
(seq (select-keys interceptor [:enter :leave :error]))
|
||||
(->> (select-keys interceptor [:enter :leave :error]) (vals) (keep identity) (seq))
|
||||
(interceptor/interceptor
|
||||
(if (error-without-arity-2? interceptor)
|
||||
(wrap-error-arity-2->1 interceptor)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
(ns reitit.pedestal-test
|
||||
(:require [clojure.test :refer [deftest testing is]]
|
||||
[reitit.pedestal :as pedestal]))
|
||||
[io.pedestal.test]
|
||||
[io.pedestal.http]
|
||||
[reitit.http :as http]
|
||||
[reitit.pedestal :as pedestal]
|
||||
[reitit.http.interceptors.exception :as exception]))
|
||||
|
||||
(deftest arities-test
|
||||
(is (= #{0} (#'pedestal/arities (fn []))))
|
||||
|
|
@ -21,3 +25,19 @@
|
|||
(is (has-2-arity-error? {:error (fn [_ _])}))
|
||||
(is (has-2-arity-error? {:error (fn [_ _ _])}))
|
||||
(is (has-2-arity-error? {:error (fn ([_]) ([_ _]))})))))
|
||||
|
||||
(deftest pedestal-e2e-test
|
||||
(let [router (pedestal/routing-interceptor
|
||||
(http/router
|
||||
[""
|
||||
{:interceptors [{:name :nop} (exception/exception-interceptor)]}
|
||||
["/ok" (fn [_] {:status 200, :body "ok"})]
|
||||
["/fail" (fn [_] (throw (ex-info "kosh" {})))]]))
|
||||
service (-> {:io.pedestal.http/request-logger nil
|
||||
:io.pedestal.http/routes []}
|
||||
(io.pedestal.http/default-interceptors)
|
||||
(pedestal/replace-last-interceptor router)
|
||||
(io.pedestal.http/create-servlet)
|
||||
(:io.pedestal.http/service-fn))]
|
||||
(is (= "ok" (:body (io.pedestal.test/response-for service :get "/ok"))))
|
||||
(is (= 500 (:status (io.pedestal.test/response-for service :get "/fail"))))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue