mirror of
https://github.com/penpot/penpot.git
synced 2025-05-21 17:56:11 +02:00
📎 Improve http server configuration
This commit is contained in:
parent
cf4f999b6a
commit
a8f5604718
2 changed files with 37 additions and 26 deletions
|
@ -143,7 +143,10 @@
|
||||||
(s/def ::host ::us/string)
|
(s/def ::host ::us/string)
|
||||||
(s/def ::http-server-port ::us/integer)
|
(s/def ::http-server-port ::us/integer)
|
||||||
(s/def ::http-server-host ::us/string)
|
(s/def ::http-server-host ::us/string)
|
||||||
|
(s/def ::http-server-max-body-size ::us/integer)
|
||||||
|
(s/def ::http-server-max-multipart-body-size ::us/integer)
|
||||||
(s/def ::http-server-io-threads ::us/integer)
|
(s/def ::http-server-io-threads ::us/integer)
|
||||||
|
(s/def ::http-server-worker-threads ::us/integer)
|
||||||
(s/def ::http-session-idle-max-age ::dt/duration)
|
(s/def ::http-session-idle-max-age ::dt/duration)
|
||||||
(s/def ::http-session-updater-batch-max-age ::dt/duration)
|
(s/def ::http-session-updater-batch-max-age ::dt/duration)
|
||||||
(s/def ::http-session-updater-batch-max-size ::us/integer)
|
(s/def ::http-session-updater-batch-max-size ::us/integer)
|
||||||
|
@ -246,7 +249,10 @@
|
||||||
::host
|
::host
|
||||||
::http-server-host
|
::http-server-host
|
||||||
::http-server-port
|
::http-server-port
|
||||||
|
::http-server-max-body-size
|
||||||
|
::http-server-max-multipart-body-size
|
||||||
::http-server-io-threads
|
::http-server-io-threads
|
||||||
|
::http-server-worker-threads
|
||||||
::http-session-idle-max-age
|
::http-session-idle-max-age
|
||||||
::http-session-updater-batch-max-age
|
::http-session-updater-batch-max-age
|
||||||
::http-session-updater-batch-max-size
|
::http-session-updater-batch-max-size
|
||||||
|
@ -341,8 +347,8 @@
|
||||||
(when (ex/ex-info? e)
|
(when (ex/ex-info? e)
|
||||||
(println ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;")
|
(println ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;")
|
||||||
(println "Error on validating configuration:")
|
(println "Error on validating configuration:")
|
||||||
(println (:explain (ex-data e))
|
(println (us/pretty-explain (ex-data e)))
|
||||||
(println ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;")))
|
(println ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"))
|
||||||
(throw e))))
|
(throw e))))
|
||||||
|
|
||||||
(def version
|
(def version
|
||||||
|
|
|
@ -32,41 +32,46 @@
|
||||||
|
|
||||||
(s/def ::handler fn?)
|
(s/def ::handler fn?)
|
||||||
(s/def ::router some?)
|
(s/def ::router some?)
|
||||||
(s/def ::port ::us/integer)
|
(s/def ::port integer?)
|
||||||
(s/def ::host ::us/string)
|
(s/def ::host string?)
|
||||||
(s/def ::name ::us/string)
|
(s/def ::name string?)
|
||||||
(s/def ::io-threads ::cf/http-server-io-threads)
|
|
||||||
|
(s/def ::max-body-size integer?)
|
||||||
|
(s/def ::max-multipart-body-size integer?)
|
||||||
|
(s/def ::io-threads integer?)
|
||||||
(s/def ::worker-threads integer?)
|
(s/def ::worker-threads integer?)
|
||||||
|
|
||||||
(defmethod ig/prep-key ::server
|
(defmethod ig/prep-key ::server
|
||||||
[_ cfg]
|
[_ cfg]
|
||||||
(merge {:name "http"
|
(merge {:name "http"
|
||||||
:port 6060
|
:port 6060
|
||||||
:host "0.0.0.0"}
|
:host "0.0.0.0"
|
||||||
|
:max-body-size (* 1024 1024 24) ; 24 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/keys :req-un [::port ::host ::name]
|
(s/and
|
||||||
:opt-un [::router ::handler ::io-threads ::worker-threads ::wrk/executor]))
|
(s/keys :req-un [::port ::host ::name ::max-body-size ::max-multipart-body-size]
|
||||||
|
:opt-un [::router ::handler ::io-threads ::worker-threads ::wrk/executor])
|
||||||
|
(fn [cfg]
|
||||||
|
(or (contains? cfg :router)
|
||||||
|
(contains? cfg :handler)))))
|
||||||
|
|
||||||
(defmethod ig/init-key ::server
|
(defmethod ig/init-key ::server
|
||||||
[_ {:keys [handler router port name host executor io-threads worker-threads] :as cfg}]
|
[_ {:keys [handler router port name host] :as cfg}]
|
||||||
(l/info :hint "starting http server"
|
(l/info :hint "starting http server" :port port :host host :name name)
|
||||||
:port port :host host :name name)
|
(let [options {:http/port port
|
||||||
|
:http/host host
|
||||||
(let [options (d/without-nils
|
:http/max-body-size (:max-body-size cfg)
|
||||||
{:http/port port
|
:http/max-multipart-body-size (:max-multipart-body-size cfg)
|
||||||
:http/host host
|
:xnio/io-threads (:io-threads cfg)
|
||||||
:ring/async true
|
:xnio/worker-threads (:worker-threads cfg)
|
||||||
:xnio/io-threads io-threads
|
:xnio/dispatch (:executor cfg)
|
||||||
:xnio/worker-threads worker-threads
|
:ring/async true}
|
||||||
:xnio/dispatch executor})
|
handler (if (some? router)
|
||||||
handler (cond
|
(wrap-router cfg router)
|
||||||
(fn? handler) handler
|
handler)
|
||||||
(some? router) (wrap-router cfg router)
|
|
||||||
:else (ex/raise :type :internal
|
|
||||||
:code :invalid-argument
|
|
||||||
:hint "Missing `handler` or `router` option."))
|
|
||||||
server (yt/server handler (d/without-nils options))]
|
server (yt/server handler (d/without-nils options))]
|
||||||
(assoc cfg :server (yt/start! server))))
|
(assoc cfg :server (yt/start! server))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue