Fork me on GitHub
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
  [_ _]
      {: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


@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

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

  {: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
   ;; content-negotiation
   ;; handle exceptions
   ;; encoding response body
   ;; decoding request body
   ;; coercing response bodys
   ;; coercing request parameters

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

michael zhou14:01:49

@ikitommi Do you have any clue? Thanks.