Skip to content

Instantly share code, notes, and snippets.

@davidsantiago
Created December 26, 2010 20:50
Show Gist options
  • Save davidsantiago/755622 to your computer and use it in GitHub Desktop.
Save davidsantiago/755622 to your computer and use it in GitHub Desktop.
;; When the wrap! is as below, the admin functions are properly wrapped, but the
;; site functions will error 500 with an NPE on session.clj:47. If I comment it and
;; uncomment the wrap! at the bottom, then the site URLs will work, but the admin
;; functions will not successfully log in, despite having the form parameters and
;; session in apparently the correct place. In fact, the post request to login is
;; identical in both cases, but it will only work if the code is as below.
;;
;; Ideally, I'd like to be able to break my routes into manageable chunks, compose
;; them, and then just wrap! once. In my reading of the source, I thought routes
;; were just functions that take a request and return a response, so shouldn't
;; you be able to wrap! them at any level?
(defroutes site-admin
(GET "/admin" {:as req} (admin/admin-home req))
(GET "/admin/login" {:as req} (admin/admin-login req))
(POST "/admin/login" {:as req} (admin/process-login req))
(GET "/admin/createPost" {:as req} (admin/create-post-form req))
(POST "/admin/createPost" {:as req} (admin/process-create-post req))
(GET "/admin/logout" {:as req} (admin/process-logout req)))
(wrap! site-admin
:params
:keyword-params
print-debug
(wrap-session {:cookie-attrs {:domain ".davidsantiago.com"}
:cookie-name "session"
:store session-store})
remove-ending-slash)
(defroutes site
(GET "/post/:post-id" [post-id] (posts/post-view post-id)))
(defroutes site-web
site-admin
site
(not-found (html [:h1 "Page not found."])))
(comment (wrap! site-web
; :params
; :keyword-params
print-debug
(wrap-session {:cookie-attrs {:domain ".davidsantiago.com"}
:cookie-name "session"
:store session-store})
remove-ending-slash))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment