danielsz / system

Reloaded components à la carte
608 stars 77 forks source link

Add support for the reitit routing library. #132

Open zendevil opened 4 years ago

zendevil commented 4 years ago

Reitit is an extremely fast and nifty routing library that deserves to be compatible with system.handler.

danielsz commented 4 years ago

I agree. But Reitit is compatible. I am using it myself. For example:

(r/ring-handler
     (r/router
      [["/" {:get index}]
       ["/faq" {:get index}]
       ["/support" {:get index}]])
     (r/routes
      (r/create-resource-handler {:path "/" :root ""})))

This plays well within a defsystem declaration.

zendevil commented 4 years ago

@danielsz. I'm using bidi currently but how do I change my app-system to use reitit? I've tried a bunch of things.

(defn app-system [config]
  (component/system-map
   :routes     (new-endpoint home-routes)
   :middleware (new-middleware {:middleware (:middleware config)})
   :handler    (-> (new-handler :router :bidi) ;; <---- :reitit option here. 
                   (component/using [:routes :middleware]))
   :http       (-> (new-web-server (:http-port config) :handler)
                   (component/using [:handler]))
   :server-info (server-info (:http-port config))))

If there were a (new-handler :router :reitit) option that would be great. I tried adding in the new-handler function of system.components.handler :reitit #(ns-resolve 'reitit.ring (symbol "ring-handler")) but it didn't work.

danielsz commented 4 years ago
(defn app-system [config]
  (component/system-map
   :routes     (new-endpoint home-routes)
   :middleware (new-middleware {:middleware (:middleware config)})
   :handler    (-> (new-handler) ;; <---- nothing needed here. 
                   (component/using [:routes :middleware]))
   :http       (-> (new-web-server (:http-port config) [:handler])
                   (component/using [:handler]))
   :server-info (server-info (:http-port config))))

With home-routes being defined like I mentioned in the first post.

(defn home-routes [_]
  (r/ring-handler
     (r/router
      [["/" {:get index}]
       ["/faq" {:get index}]
       ["/support" {:get index}]])
     (r/routes
      (r/create-resource-handler {:path "/" :root ""}))))
zendevil commented 4 years ago

Removing :router :bidi from (new-handler) gives me the following error:

Execution error at system.components.handler/new-handler$fn (handler.clj:79).
No namespace: compojure.core found
danielsz commented 4 years ago

You would have to include compojure as a dependency in your project to get rid of the message.

zendevil commented 4 years ago

Yes, I have tried that but still get the error.

zendevil commented 4 years ago

Hi @danielsz, I still get the compojure error after adding the compojure dependency. Why might this be?