Skip to content

Commit

Permalink
compojure.handler namespace is deprecated in favor of ring-defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsz committed Aug 10, 2014
1 parent 82d5433 commit 694d6f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion example-project/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
;;
[compojure "1.1.8"] ; Or routing lib of your choice
[ring "1.3.0"]
[ring/ring-defaults "0.1.1"]
[hiccup "1.0.5"] ; Optional, just for HTML
[org.clojure/core.match "0.2.1"] ; Optional but quite handly
[ring-anti-forgery "1.0.0"] ; Optional, for easy CSRF protection
]

:plugins
Expand Down
39 changes: 20 additions & 19 deletions example-project/src/example/my_app.cljx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#+clj
(:require
[clojure.string :as str]
[compojure.core :as comp :refer (defroutes routes GET POST)]
[compojure.core :as comp :refer (defroutes GET POST)]
[compojure.route :as route]
[compojure.handler :as comp-handler]
[ring.middleware.defaults :refer [wrap-defaults site-defaults]]
[hiccup.core :as hiccup]
[org.httpkit.server :as http-kit-server]
[clojure.core.match :as match :refer (match)]
Expand Down Expand Up @@ -95,27 +95,28 @@
{:status 200 :session (assoc session :uid user-id)}))

#+clj
(defroutes my-ring-handler
(->
(routes
(GET "/" req (landing-pg-handler req))
;;
(GET "/chsk" req (ring-ajax-get-or-ws-handshake req))
(POST "/chsk" req (ring-ajax-post req))
(POST "/login" req (login! req))
;;
(route/resources "/") ; Static files, notably public/main.js (our cljs target)
(route/not-found "<h1>Page not found</h1>"))
(defroutes my-routes
(GET "/" req (landing-pg-handler req))
;;
(GET "/chsk" req (ring-ajax-get-or-ws-handshake req))
(POST "/chsk" req (ring-ajax-post req))
(POST "/login" req (login! req))
;;
(route/resources "/") ; Static files, notably public/main.js (our cljs target)
(route/not-found "<h1>Page not found</h1>"))

;;; Middleware
#+clj
(def my-middleware
(assoc-in site-defaults [:security :anti-forgery]
{:read-token (fn [req] (-> req :params :csrf-token))}))

;; Sente adds a :csrf-token param to Ajax requests:
(ring-anti-forgery/wrap-anti-forgery
{:read-token (fn [req] (-> req :params :csrf-token))})
#+clj
(def my-ring-handler
(wrap-defaults my-routes my-middleware))

compojure.handler/site))
#+clj
(defonce http-server_ (atom nil))

#+clj (defonce http-server_ (atom nil))
#+clj
(defn stop-http-server! []
(when-let [current-server @http-server_]
Expand Down

0 comments on commit 694d6f9

Please sign in to comment.