17

I have two different web applications in Clojure developed with Compojure. Each use defroutes to create its handler.

How can I combine the two different definitions of defroutes into one defroute? I want to reuse the routes of the first app into the second.

z1naOK9nu8iY5A
  • 903
  • 7
  • 22

1 Answers1

27

You can use compojure.core/routes to combine routes:

 (def my-handler
    (routes some-handler
            some-other-handler))
Conan
  • 2,288
  • 1
  • 28
  • 42
Joost Diepenmaat
  • 17,633
  • 3
  • 44
  • 53
  • I tried (def route1 [(GET "/" [] (index-page)) (route/resources "/") (route/not-found "Page not found")]) (def allroutes (concat routes1 routes2)) (def app (handler/site (apply routes allroutes))) But the second routes are not used – z1naOK9nu8iY5A Nov 30 '11 at 16:48
  • 4
    Ok I found the error: one need to take care of not having a route-not-found handler in the first list... – z1naOK9nu8iY5A Nov 30 '11 at 16:54
  • 1
    "Ok I found the error: one need to take care of not having a route-not-found handler in the first list... –" please elaborate? what solution did you discover? – PPPaul Feb 01 '13 at 20:36
  • 5
    Maybe it's kinda late, but I think the point was that the `not-found` route should be last in the list of routes, otherwise it will match all the url and the app will always return "Not Found" – ak. Aug 09 '13 at 12:22