Fork me on GitHub
#pedestal
<
2017-02-25
>
kirill.salykin09:02:28

Hi all, I am using pedestal based on Stuart Sierra component. Basically it is only 2 components now: Pedestal and Datomic. I am trying to inject datomic connection to intercepctors chain. But I keep getting this error: "You're trying to use something as an interceptor that isn't supported by the protocol; Perhaps you need to extend it?"

(defrecord Pedestal [service-map service db]
  component/Lifecycle
  (start [component]
    (print (str "DB:" db))
    (if service
      component
      (-> service-map
          (assoc :http/routes (routes/routes db))
          http/create-server
          http/start
          (assoc component :service))))
  (stop [component]
    (when service (http/stop service))
    (assoc component :service nil)))
(defn routes [db-component]
  (let [session-inter (session {:store (cookie/cookie-store)})
        conn (:conn db-component)
        attach-conn (attach-to-request :conn conn)]
    (route/expand-routes
     #{
       ["/"        :get  [attach-conn session-inter authenticate guard 'root]]
       ["/sign-up" :get  [attach-conn session-inter 'show-sign-up]]
       ["/sign-up" :post [attach-conn session-inter (body-params) keyword-params 'sign-up]]
       ["/sign-in" :get  [attach-conn session-inter 'show-sign-in]]
       ["/sign-in" :post [attach-conn session-inter (body-params) keyword-params 'sign-in]]
       })))
(defn attach-to-request [name obj]
  (interceptor
   {:name ::attach-to-req
    :enter (fn [ctx]
               (assoc-in ctx [:request name] obj))}))
Please advice what I am doing wrong. Thanks!

mavbozo10:02:38

@kirill.salykin i suspect this line (assoc component :service)

mavbozo10:02:22

basically it will be expanded to (assoc (http/start ...) component service) while what you want is (assoc component :service (http/start ...))

kirill.salykin10:02:59

looks like this is the reason

mavbozo10:02:31

I find it helpful for me to split the Pedestal component into 2 components: Pedestal Service component just for preparing the service map for Pedestal Server component which is responsible for creating/starting/stopping the server

kirill.salykin11:02:07

sounds interesting

kirill.salykin11:02:19

I also found pedestal component from Sierra

kirill.salykin11:02:25

trying this now

kirill.salykin11:02:27

thanks for help!