mirror of
https://github.com/penpot/penpot.git
synced 2025-03-11 07:11:32 -05:00
🔥 Remove ratelimit (delegate this task to nginx).
This commit is contained in:
parent
1a82fc28d3
commit
c0b3618331
3 changed files with 1 additions and 61 deletions
|
@ -29,9 +29,6 @@
|
|||
{:local/root "vendor/sodi"
|
||||
:deps/manifest :pom}
|
||||
|
||||
io.github.resilience4j/resilience4j-core {:mvn/version "1.2.0"}
|
||||
io.github.resilience4j/resilience4j-ratelimiter {:mvn/version "1.2.0"}
|
||||
|
||||
lambdaisland/uri {:mvn/version "1.1.0"}
|
||||
|
||||
danlentz/clj-uuid {:mvn/version "0.1.9"}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
[uxbox.http.session :as session]
|
||||
[uxbox.http.handlers :as handlers]
|
||||
[uxbox.http.debug :as debug]
|
||||
[uxbox.http.ratelimit :as rl]
|
||||
[uxbox.http.ws :as ws]
|
||||
[vertx.core :as vc]
|
||||
[vertx.http :as vh]
|
||||
|
@ -38,12 +37,6 @@
|
|||
interceptors/format-response-body
|
||||
(vxi/errors errors/handle)]
|
||||
|
||||
login-handler (rl/ratelimit handlers/login-handler
|
||||
{:limit 10
|
||||
:period 1000
|
||||
:timeout 200
|
||||
:name "login-handler"})
|
||||
|
||||
routes [["/sub/:file-id" {:interceptors [(vxi/cookies)
|
||||
(vxi/cors cors-opts)
|
||||
interceptors/format-response-body
|
||||
|
@ -52,7 +45,7 @@
|
|||
|
||||
["/api" {:interceptors interceptors}
|
||||
["/echo" {:all handlers/echo-handler}]
|
||||
["/login" {:post login-handler}]
|
||||
["/login" {:post handlers/login-handler}]
|
||||
["/logout" {:post handlers/logout-handler}]
|
||||
["/debug"
|
||||
["/emails" {:get debug/emails-list}]
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; defined by the Mozilla Public License, v. 2.0.
|
||||
;;
|
||||
;; Copyright (c) 2016-2019 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
(ns uxbox.http.ratelimit
|
||||
"Rate limit"
|
||||
(:require
|
||||
[clojure.spec.alpha :as s]
|
||||
[uxbox.common.exceptions :as ex]
|
||||
[uxbox.core :refer [system]]
|
||||
[vertx.core :as vc]
|
||||
[promesa.core :as p]
|
||||
[promesa.exec :as pe])
|
||||
(:import
|
||||
io.github.resilience4j.ratelimiter.RateLimiter
|
||||
io.github.resilience4j.ratelimiter.RateLimiterConfig
|
||||
io.github.resilience4j.ratelimiter.RateLimiterRegistry
|
||||
java.util.concurrent.CompletableFuture
|
||||
java.util.function.Supplier
|
||||
java.time.Duration))
|
||||
|
||||
;; --- Rate Limiter
|
||||
|
||||
(def ^:private registry (RateLimiterRegistry/ofDefaults))
|
||||
|
||||
(defn- opts->rate-limiter-config
|
||||
[{:keys [limit period timeout] :as opts}]
|
||||
(let [custom (RateLimiterConfig/custom)]
|
||||
(.limitRefreshPeriod custom (Duration/ofMillis period))
|
||||
(.limitForPeriod custom limit)
|
||||
(.timeoutDuration custom (Duration/ofMillis timeout))
|
||||
(.build custom)))
|
||||
|
||||
(defn ratelimit
|
||||
[f {:keys [name] :as opts}]
|
||||
(let [config (opts->rate-limiter-config opts)
|
||||
rl (.rateLimiter registry name config)]
|
||||
(fn [& args]
|
||||
(let [ctx (vc/get-or-create-context system)]
|
||||
(-> (pe/run! #(when-not (.acquirePermission rl 1)
|
||||
(ex/raise :type :ratelimit
|
||||
:code :timeout
|
||||
:context {:name name})))
|
||||
(vc/handle-on-context)
|
||||
(p/bind (fn [_] (p/do! (apply f args)))))))))
|
Loading…
Add table
Reference in a new issue