valpackett / ring-ratelimit

Rate limiting middleware for Clojure Ring | now on https://codeberg.org/valpackett/ring-ratelimit
https://codeberg.org/valpackett/ring-ratelimit
79 stars 7 forks source link

The Advanced example doesn't work for me #1

Closed yayitswei closed 11 years ago

yayitswei commented 11 years ago

Does it work to have handlers inside a route definition? This returns a null on every request.

(defroutes easy-handler
  (GET "/" [] "easy"))

(defroutes hard-handler
  (GET "/" [] "hard"))

(defroutes awesome-routes
  (ANY "/easy-things" []
    (-> easy-handler
        (wrap-ratelimit default-limit)))
  (ANY "/hard-things" []
    (-> hard-handler
        (wrap-ratelimit
          (assoc default-limit :limits
            [(-> 30 limit
                 (wrap-limit-param :query)
                 wrap-limit-user)
             (-> 10 limit
                 (wrap-limit-param :query)
                 wrap-limit-ip)])))))
valpackett commented 11 years ago

Well, I suck at Compojure :D

I'll try to fix the example.

On Sep 16, 2013, at 1:59 PM, Wei Hsu notifications@github.com wrote:

Does it work to have handlers inside a route definition? This returns a null on every request.

(defroutes easy-handler (GET "/" [] "easy"))

(defroutes hard-handler (GET "/" [] "hard"))

(defroutes awesome-routes (ANY "/easy-things" [](-> easy-handler %28wrap-ratelimit default-limit%29)) (ANY "/hard-things" [](-> hard-handler %28wrap-ratelimit %28assoc default-limit :limits [%28-> 30 limit %28wrap-limit-param :query%29 wrap-limit-user%29 %28-> 10 limit %28wrap-limit-param :query%29 wrap-limit-ip%29]%29%29))) — Reply to this email directly or view it on GitHub.

valpackett commented 11 years ago

Looks like everything works when easy-handler and hard-handler are regular Ring functions, not Compojure routes…