Skip to content

olenhad/ring-filter-routes

Repository files navigation

ring-filter-routes

Very simple route filtering middleware To use, add to your project's dependencies:

:dependencies [[org.clojure/clojure "1.4.0"]
               [ring-filter-routes "0.1.1"]]

Usage

Takes a vector of filter rules. Each rule is a hash-map of :url a :check function and an :else-action to execute if the check fails. For instance

(def app-filters
  [{:url "/moria"
    :check (fn [req] (= (session/current-user) :balrog))
    :else-action (fn [req] (ring/redirect "/shallnotpass"))}

   {:url #"/winterfell/.*"
    :check (fn [req] (= (westeros/season) :winter))
    :else-action (fn [req] (do (println "Winter is Coming...")
                           (ring/redirect "/season1")))}])
;in your app def just add
(def app
  (-> (handler/site main-routes)
      (wrap-base-url)
      (wrap-filter-routes app-filters)))

The function passed as :else-action is executed instead of (app req), so make sure you add an appropriate ring response.

License

Copyright © 2013 Omer Iqbal

Distributed under the Eclipse Public License, the same as Clojure.

About

simple route filtering middleware for ring

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published