Created
October 1, 2013 17:05
-
-
Save duckyuck/6781773 to your computer and use it in GitHub Desktop.
Applying middleware to selected routes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns composable-compojure.handler | |
(:use compojure.core) | |
(:require [compojure.handler :as handler] | |
[ring.util.response :refer [response]])) | |
(defn middleware | |
[handler value] | |
(fn [request] | |
(handler (update-in request [:from-middleware] (partial cons value))))) | |
(defn respond [request] (response (str ":from-middleware = " (:from-middleware request)))) | |
` | |
(def foo-routes | |
(context | |
"/foo" [] | |
(-> (routes | |
(GET "/" request (respond request))) | |
(middleware "foo")))) | |
(def bar-routes | |
(context | |
"/bar" [] | |
(-> (routes | |
(GET "/" request (respond request))) | |
(middleware "bar")))) | |
(def handler | |
(handler/site | |
(routes foo-routes | |
bar-routes))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment