Fork me on GitHub
#reitit
<
2020-01-16
>
michael zhou12:01:35

hello everyone! When I use duct+pedestal+reitit, i get an error.

michael zhou12:01:07

route-spec error

michael zhou12:01:32

(s/def ::x decimal?)
(s/def ::y decimal?)
(s/def ::total int?)
(s/def ::math-request (s/keys :req-un [::x ::y]))
(s/def ::math-response (s/keys :req-un [::total]))

(defn interceptor [number]
  {:enter (fn [ctx] (update-in ctx [:request :number] (fnil + 0) number))})

(defmethod ig/init-key :yzcx/routes
  [_ _]
   ["/plus"
      {:get {;:summary "plus with spec query parameters"
             :parameters {:query ::math-request}
            ; :responses {200 {:body ::math-response}}
             :handler (fn [{{{:keys [x y]} :query} :parameters}]
                        {:status 200
                         :body {:total (+ x y)}})
             :interceptors [(interceptor 1)]
             }
       :post {;:summary "plus with spec body parameters"
              :parameters {:body ::math-request}
              ;:responses {200 {:body ::math-response}}
              :handler (fn [{{{:keys [x y]} :body} :parameters}]
                         {:status 200
                          :body {:total (+ x y)}})
              :interceptors [(interceptor 1)]
              }}]
  )

michael zhou12:01:50

Anyone know how to fix this? Thanks

ikitommi14:01:11

@zhoumin79 that's an pedestal error, can't help there. Some missconfig at the border. The reitit-pedestal example should work, I would start to compare with that

michael zhou14:01:11

:duct.server/pedestal
  {:service #:io.pedestal.http {:router #ig/ref :duct.router/reitit
                                :host   #duct/env "SERVER_HOST"
                                :port   #duct/env ["SERVER_PORT" Int :or 3000]}}

  :duct.router/reitit
  {:routes #ig/ref :yzcx/routes
   }

  :yzcx/routes {}

michael zhou14:01:45

this is my relate config from edn

michael zhou14:01:00

(def common-interceptors
  [;; query-params & form-params
   (parameters/parameters-interceptor)
   ;; content-negotiation
   (muuntaja/format-negotiate-interceptor)
   ;; handle exceptions
   ;(exception/exception-interceptor)
   ;; encoding response body
   (muuntaja/format-response-interceptor)
   ;; decoding request body
   (muuntaja/format-request-interceptor)
   ;; coercing response bodys
   (coercion/coerce-response-interceptor)
   ;; coercing request parameters
   (coercion/coerce-request-interceptor)])

(defmethod ig/init-key :duct.router/reitit
  [_ {:keys [routes]}]
  (http/router
   [routes]
   {:data {:coercion     reitit.coercion.spec/coercion
           :interceptors common-interceptors}}))

michael zhou14:01:49

@ikitommi Do you have any clue? Thanks.