Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the reitit routing library. #132

Open
zendevil opened this issue Feb 19, 2020 · 7 comments
Open

Add support for the reitit routing library. #132

zendevil opened this issue Feb 19, 2020 · 7 comments

Comments

@zendevil
Copy link

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

@danielsz
Copy link
Owner

danielsz commented Feb 20, 2020

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
Copy link
Author

zendevil commented Feb 21, 2020

@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
Copy link
Owner

danielsz commented Feb 22, 2020

(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
Copy link
Author

zendevil commented Feb 29, 2020

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
Copy link
Owner

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

@zendevil
Copy link
Author

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

@zendevil
Copy link
Author

zendevil commented Mar 6, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants