This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-20
Channels
- # 100-days-of-code (2)
- # aleph (53)
- # architecture (2)
- # aws (3)
- # beginners (230)
- # boot (15)
- # calva (3)
- # cider (19)
- # cljs-dev (1)
- # clojure (139)
- # clojure-conj (3)
- # clojure-italy (47)
- # clojure-nl (19)
- # clojure-spec (26)
- # clojure-uk (98)
- # clojurescript (152)
- # clojutre (4)
- # core-async (22)
- # cursive (5)
- # datomic (48)
- # emacs (11)
- # events (1)
- # figwheel-main (219)
- # fulcro (15)
- # instaparse (3)
- # jobs (4)
- # jobs-rus (1)
- # leiningen (30)
- # luminus (8)
- # off-topic (67)
- # onyx (5)
- # pedestal (16)
- # re-frame (1)
- # reagent (4)
- # reitit (31)
- # ring (8)
- # ring-swagger (3)
- # shadow-cljs (115)
- # specter (4)
- # videos (1)
- # vim (20)
- # yada (15)
Hi, In my use case, I need to have different middle-ware for specific routes. This is the code:
(ns my-api.handler
(:require [compojure.api.sweet :refer :all]
[ring.util.http-response :refer :all]))
(defn echo0[handler]
(fn [request]
(prn "ECHO0" #_request)
(handler request)
))
(defn echo1[handler]
(fn [request]
(prn "ECHO1" #_request)
(handler request)
))
(def app
(api
(middleware [echo0] (swagger-routes))
(context "/api" []
:middleware [echo1]
(GET "/test" [] (ok "1")))))
However, when I run the code echo0
is invoked for /api/test
as well. Is there is any way to make those completely separate?@happy.lisper good question. The middleware
is removed in 2.0.0 in favour of route-middleware
, which should do what you want. The root cause here is that in Compojure, the routing tree is an application where the middleware are applied in-place - there is no good way to delay the computation to see if the route will eventually match.