routes are now automatically discovered and added to the ring handler
This commit is contained in:
parent
0112dc515a
commit
cfee97fd95
|
@ -1,23 +1,18 @@
|
|||
(ns blarg.handler
|
||||
(:use blarg.routes.home
|
||||
blarg.routes.posts
|
||||
blarg.routes.auth
|
||||
blarg.routes.files
|
||||
blarg.routes.rss
|
||||
blarg.routes.accessrules
|
||||
blarg.config
|
||||
ring.middleware.head
|
||||
compojure.core)
|
||||
(:require [noir.util.middleware :refer [app-handler]]
|
||||
[noir.response :as resp]
|
||||
[compojure.core :refer [defroutes]]
|
||||
[compojure.route :as route]
|
||||
[compojure.response :refer [render]]
|
||||
[taoensso.timbre :as timbre]
|
||||
[taoensso.timbre.appenders.rotor :as rotor]
|
||||
[clj-jtwig.core :as jtwig]
|
||||
[clj-jtwig.web.middleware :refer [wrap-servlet-context-path]]
|
||||
[blarg.config :refer [config-val]]
|
||||
[blarg.views.layout :as layout]
|
||||
[blarg.models.db :as db]))
|
||||
[blarg.models.db :as db]
|
||||
[blarg.routes.accessrules :refer [auth-required]]
|
||||
[blarg.route-utils :refer [find-routes]]))
|
||||
|
||||
(defroutes app-routes
|
||||
(route/resources "/")
|
||||
|
@ -60,8 +55,10 @@
|
|||
:params {:errorInfo e}
|
||||
:status 500)))))
|
||||
|
||||
(def app (app-handler
|
||||
[auth-routes home-routes posts-routes files-routes rss-routes app-routes]
|
||||
:middleware [wrap-exceptions wrap-servlet-context-path]
|
||||
:access-rules [{:redirect "/unauthorized" :rule auth-required}]
|
||||
:formats [:json-kw :edn]))
|
||||
(defonce routes (find-routes "blarg.routes." app-routes))
|
||||
|
||||
(defonce app (app-handler
|
||||
routes
|
||||
:middleware [wrap-exceptions wrap-servlet-context-path]
|
||||
:access-rules [{:redirect "/unauthorized" :rule auth-required}]
|
||||
:formats [:json-kw :edn]))
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
[noir.util.route])
|
||||
(:require [blarg.views.layout :as layout]
|
||||
[blarg.models.users :as users]
|
||||
[blarg.route-utils :refer [register-routes]]
|
||||
[ring.util.response :refer [status]]
|
||||
[ring.middleware.head :refer [wrap-head]]
|
||||
[noir.session :as session]
|
||||
|
@ -37,7 +38,7 @@
|
|||
(defn handle-unauthorized []
|
||||
(layout/render "unauthorized.html" :status 401))
|
||||
|
||||
(defroutes auth-routes
|
||||
(register-routes auth-routes
|
||||
(GET "/unauthorized" [] (handle-unauthorized))
|
||||
(GET "/login" [] (login-page))
|
||||
(POST "/login" [id pass] (handle-login id pass))
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
(:require [blarg.views.layout :as layout]
|
||||
[blarg.models.files :as files]
|
||||
[blarg.routes.auth :as auth]
|
||||
[blarg.route-utils :refer [register-routes]]
|
||||
[noir.response :as resp]
|
||||
[noir.session :as session]))
|
||||
|
||||
|
@ -69,7 +70,7 @@
|
|||
(resp/content-type (:content_type file) (:data file))
|
||||
(resp/redirect "/notfound")))
|
||||
|
||||
(defroutes files-routes
|
||||
(register-routes files-routes
|
||||
(GET "/listfiles" [] (restricted (list-files "/")))
|
||||
(GET "/listfiles/*" [*] (restricted (list-files *)))
|
||||
(POST "/uploadfile" [path file returnpath] (restricted (handle-new-file (ensure-prefix-suffix path "/") file returnpath)))
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
[compojure.core]
|
||||
[blarg.routes.helpers])
|
||||
(:require [blarg.views.layout :as layout]
|
||||
[blarg.route-utils :refer [register-routes]]
|
||||
[noir.response :as resp]))
|
||||
|
||||
(defn about-page []
|
||||
|
@ -15,7 +16,7 @@
|
|||
"projects.html"
|
||||
:params {:htmlTitle (->html-title ["Projects"])}))
|
||||
|
||||
(defroutes home-routes
|
||||
(register-routes home-routes
|
||||
(GET "/about" [] (about-page))
|
||||
(GET "/projects" [] (projects-page))
|
||||
(GET "/toslug" [text] (resp/json {:slug (if text (->slug text))})))
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
[noir.session :as session]
|
||||
[blarg.views.layout :as layout]
|
||||
[blarg.models.posts :as posts]
|
||||
[blarg.routes.auth :as auth]))
|
||||
[blarg.routes.auth :as auth]
|
||||
[blarg.route-utils :refer [register-routes]]))
|
||||
|
||||
(defn string->tags [s]
|
||||
(->> (clojure.string/split s #",")
|
||||
|
@ -121,7 +122,7 @@
|
|||
(resp/redirect "/")
|
||||
(throw (Exception. "Error deleting post."))))
|
||||
|
||||
(defroutes posts-routes
|
||||
(register-routes posts-routes
|
||||
(GET "/" [page] (list-page (parse-int page 0)))
|
||||
(GET
|
||||
["/:year/:month/:day/:slug/" :year #"[0-9]{4}" :month #"[0-9]{1,2}" :day #"[0-9]{1,2}" :slug #"(.*)"]
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
[clj-rss.core :as rss]
|
||||
[clj-time.core]
|
||||
[clj-time.coerce]
|
||||
[blarg.models.posts :as posts]))
|
||||
[blarg.models.posts :as posts]
|
||||
[blarg.route-utils :refer [register-routes]]))
|
||||
|
||||
(def rss-title "blarg.ca")
|
||||
(def rss-site-url "http://www.blarg.ca/")
|
||||
|
@ -27,5 +28,5 @@
|
|||
:description (md/md-to-html-string (:body post))}))
|
||||
(doall))))))
|
||||
|
||||
(defroutes rss-routes
|
||||
(register-routes rss-routes
|
||||
(GET "/rss" [] (handle-rss)))
|
||||
|
|
Reference in a new issue