-
-
Save apeckham/d30169162d96cb2c42722743f1fdcd6e to your computer and use it in GitHub Desktop.
This file contains 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 mountie.core | |
(:require [ring.adapter.jetty :refer [run-jetty]] | |
[ring.middleware.reload :refer [wrap-reload]] | |
[ring.middleware.ratelimit :refer [wrap-ratelimit ip-limit]] | |
[ring.middleware.ratelimit.redis :refer [redis-backend]] | |
[mount.core :as m]) | |
(:gen-class)) | |
(defn handler [request] | |
{:status 200 | |
:headers {"Content-Type" "text/html"} | |
:body "Hello World"}) | |
(m/defstate backend :start (redis-backend)) | |
(def app | |
(-> handler | |
(wrap-ratelimit {:backend backend}))) | |
(defn -main [& args] | |
(m/start) | |
(run-jetty (wrap-reload #'app) {:port 3000})) | |
;; when you GET /, `wrap-ratelimit` tries to connect to the backend before it was mount/started | |
;; java.lang.IllegalArgumentException: No implementation of method: :available? of protocol: #'ring.middleware.ratelimit.backend/Backend found for class: mount.core.DerefableState | |
;; at clojure.core$_cache_protocol_fn.invokeStatic(core_deftype.clj:583) | |
;; at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:575) | |
;; at ring.middleware.ratelimit.backend$eval1108$fn__1109$G__1099__1114.invoke(backend.clj:3) | |
;; at ring.middleware.ratelimit$wrap_ratelimit$fn__1243.invoke(ratelimit.clj:37) | |
;; at clojure.lang.Var.invoke(Var.java:381) | |
;; at ring.middleware.reload$wrap_reload$fn__1063.invoke(reload.clj:39) | |
;; at ring.adapter.jetty$proxy_handler$fn__488.invoke(jetty.clj:25) | |
;; at ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle(Unknown Source) | |
;; at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) | |
;; at org.eclipse.jetty.server.Server.handle(Server.java:499) | |
;; at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311) | |
;; at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:258) | |
;; at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544) | |
;; at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635) | |
;; at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555) | |
;; at java.lang.Thread.run(Thread.java:745) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment