Jonathon McKitrick
unread,Aug 7, 2014, 8:17:15 AM8/7/14Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to clo...@googlegroups.com
I'm serving up some html and js content, and using handler/site for that. I have a separate handler/api group of routes under the "/api" context.
If I include the api routes before the site routes, the site works fine. If the www routes come first, the api calls fail, probably because the (route/resources "/") at the end of the site routes catches that call and returns null.
OTOH, if I try to use friend with the api routes, it breaks the friend wrapping of the www calls.
(defroutes api-routes
(context "/api" []
.....
(route/not-found "ERROR")))
(defroutes www-routes
(GET "/admin" req (friend/authorize #{::admin} "Admin only"))
(GET "/authorized" req (friend/authorize #{::user} "Users only"))
(GET "/home" [] (response/file-response "home.html" {:root "resources/public"}))
(GET "/login" [] (response/file-response "login.html" {:root "resources/public"}))
(friend/logout (ANY "/logout" req (response/redirect "/")))
(GET "/" [] (response/redirect "index.html"))
(route/resources "/")
(route/not-found "Not Found"))
(def app
(routes
(-> www-routes
(friend/authenticate {;:allow-anon? true
;;:login-uri "/login.html"
;:default-landing-uri "/"
;:redirect-on-auth? "/home"
;:unauthorized-handler #(response/status (response/response "NO") 401)
;:login-failure-handler #(response/response "OOPS")
:credential-fn (partial creds/bcrypt-credential-fn users)
:workflows [(workflows/interactive-form)]})
;;(wrap-resource "public")
;wrap-content-type
;wrap-not-modified
;;wrap-reload
handler/site)
(-> api-routes
handler/api
;;wrap-reload
wrap-restful-format)))