mirror of
https://github.com/penpot/penpot.git
synced 2025-02-15 03:28:25 -05:00
✨ Add better spec validation on http module
This commit is contained in:
parent
3cf4a3facc
commit
0c48f76911
2 changed files with 41 additions and 33 deletions
|
@ -46,46 +46,53 @@
|
||||||
(s/def ::max-body-size integer?)
|
(s/def ::max-body-size integer?)
|
||||||
(s/def ::max-multipart-body-size integer?)
|
(s/def ::max-multipart-body-size integer?)
|
||||||
(s/def ::io-threads integer?)
|
(s/def ::io-threads integer?)
|
||||||
(s/def ::worker-threads integer?)
|
|
||||||
|
|
||||||
(defmethod ig/prep-key ::server
|
(defmethod ig/prep-key ::server
|
||||||
[_ cfg]
|
[_ cfg]
|
||||||
(merge {:name "http"
|
(merge {::port 6060
|
||||||
:port 6060
|
::host "0.0.0.0"
|
||||||
:host "0.0.0.0"
|
::max-body-size (* 1024 1024 30) ; 30 MiB
|
||||||
:max-body-size (* 1024 1024 30) ; 30 MiB
|
::max-multipart-body-size (* 1024 1024 120)} ; 120 MiB
|
||||||
:max-multipart-body-size (* 1024 1024 120)} ; 120 MiB
|
|
||||||
(d/without-nils cfg)))
|
(d/without-nils cfg)))
|
||||||
|
|
||||||
(defmethod ig/pre-init-spec ::server [_]
|
(defmethod ig/pre-init-spec ::server [_]
|
||||||
(s/and
|
(s/keys :req [::port ::host]
|
||||||
(s/keys :req-un [::port ::host ::name ::max-body-size ::max-multipart-body-size]
|
:opt [::max-body-size
|
||||||
:opt-un [::router ::handler ::io-threads ::worker-threads ::wrk/executor])
|
::max-multipart-body-size
|
||||||
(fn [cfg]
|
::router
|
||||||
(or (contains? cfg :router)
|
::handler
|
||||||
(contains? cfg :handler)))))
|
::io-threads
|
||||||
|
::wrk/executor]))
|
||||||
|
|
||||||
(defmethod ig/init-key ::server
|
(defmethod ig/init-key ::server
|
||||||
[_ {:keys [handler router port name host] :as cfg}]
|
[_ {:keys [::handler ::router ::host ::port] :as cfg}]
|
||||||
(l/info :hint "starting http server" :port port :host host :name name)
|
(l/info :hint "starting http server" :port port :host host)
|
||||||
(let [options {:http/port port
|
(let [options {:http/port port
|
||||||
:http/host host
|
:http/host host
|
||||||
:http/max-body-size (:max-body-size cfg)
|
:http/max-body-size (::max-body-size cfg)
|
||||||
:http/max-multipart-body-size (:max-multipart-body-size cfg)
|
:http/max-multipart-body-size (::max-multipart-body-size cfg)
|
||||||
:xnio/io-threads (:io-threads cfg)
|
:xnio/io-threads (::io-threads cfg)
|
||||||
:xnio/dispatch (:executor cfg)
|
:xnio/dispatch (::wrk/executor cfg)
|
||||||
:ring/async true}
|
:ring/async true}
|
||||||
|
|
||||||
handler (if (some? router)
|
handler (cond
|
||||||
|
(some? router)
|
||||||
(wrap-router router)
|
(wrap-router router)
|
||||||
|
|
||||||
handler)
|
(some? handler)
|
||||||
server (yt/server handler (d/without-nils options))]
|
handler
|
||||||
(assoc cfg :server (yt/start! server))))
|
|
||||||
|
:else
|
||||||
|
(throw (UnsupportedOperationException. "handler or router are required")))
|
||||||
|
|
||||||
|
options (d/without-nils options)
|
||||||
|
server (yt/server handler options)]
|
||||||
|
|
||||||
|
(assoc cfg ::server (yt/start! server))))
|
||||||
|
|
||||||
(defmethod ig/halt-key! ::server
|
(defmethod ig/halt-key! ::server
|
||||||
[_ {:keys [server name port] :as cfg}]
|
[_ {:keys [::server ::port] :as cfg}]
|
||||||
(l/info :msg "stopping http server" :name name :port port)
|
(l/info :msg "stopping http server" :port port)
|
||||||
(yt/stop! server))
|
(yt/stop! server))
|
||||||
|
|
||||||
(defn- not-found-handler
|
(defn- not-found-handler
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.db :as-alias db]
|
[app.db :as-alias db]
|
||||||
[app.email :as-alias email]
|
[app.email :as-alias email]
|
||||||
|
[app.http :as-alias http]
|
||||||
[app.http.access-token :as-alias actoken]
|
[app.http.access-token :as-alias actoken]
|
||||||
[app.http.assets :as-alias http.assets]
|
[app.http.assets :as-alias http.assets]
|
||||||
[app.http.awsns :as http.awsns]
|
[app.http.awsns :as http.awsns]
|
||||||
|
@ -234,15 +235,15 @@
|
||||||
::http.client/client (ig/ref ::http.client/client)
|
::http.client/client (ig/ref ::http.client/client)
|
||||||
::wrk/executor (ig/ref ::wrk/executor)}
|
::wrk/executor (ig/ref ::wrk/executor)}
|
||||||
|
|
||||||
:app.http/server
|
::http/server
|
||||||
{:port (cf/get :http-server-port)
|
{::http/port (cf/get :http-server-port)
|
||||||
:host (cf/get :http-server-host)
|
::http/host (cf/get :http-server-host)
|
||||||
:router (ig/ref :app.http/router)
|
::http/router (ig/ref ::http/router)
|
||||||
:metrics (ig/ref ::mtx/metrics)
|
::http/metrics (ig/ref ::mtx/metrics)
|
||||||
:executor (ig/ref ::wrk/executor)
|
::http/executor (ig/ref ::wrk/executor)
|
||||||
:io-threads (cf/get :http-server-io-threads)
|
::http/io-threads (cf/get :http-server-io-threads)
|
||||||
:max-body-size (cf/get :http-server-max-body-size)
|
::http/max-body-size (cf/get :http-server-max-body-size)
|
||||||
:max-multipart-body-size (cf/get :http-server-max-multipart-body-size)}
|
::http/max-multipart-body-size (cf/get :http-server-max-multipart-body-size)}
|
||||||
|
|
||||||
::ldap/provider
|
::ldap/provider
|
||||||
{:host (cf/get :ldap-host)
|
{:host (cf/get :ldap-host)
|
||||||
|
|
Loading…
Add table
Reference in a new issue