0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-12 23:11:23 -05:00

📎 Improve api ergonomy of http server module

This commit is contained in:
Andrey Antukh 2022-03-11 09:50:49 +01:00
parent 52029f83ef
commit cf4f999b6a
2 changed files with 12 additions and 9 deletions

View file

@ -35,8 +35,8 @@
(s/def ::port ::us/integer)
(s/def ::host ::us/string)
(s/def ::name ::us/string)
(s/def ::executors (s/map-of keyword? ::wrk/executor))
(s/def ::io-threads ::cf/http-server-io-threads)
(s/def ::worker-threads integer?)
(defmethod ig/prep-key ::server
[_ cfg]
@ -46,18 +46,21 @@
(d/without-nils cfg)))
(defmethod ig/pre-init-spec ::server [_]
(s/keys :req-un [::port ::host ::name ::executors]
:opt-un [::router ::handler ::io-threads]))
(s/keys :req-un [::port ::host ::name]
:opt-un [::router ::handler ::io-threads ::worker-threads ::wrk/executor]))
(defmethod ig/init-key ::server
[_ {:keys [handler router port name host executors] :as cfg}]
[_ {:keys [handler router port name host executor io-threads worker-threads] :as cfg}]
(l/info :hint "starting http server"
:port port :host host :name name)
(let [options {:http/port port
:http/host host
:ring/async true
:xnio/dispatch (:default executors)}
(let [options (d/without-nils
{:http/port port
:http/host host
:ring/async true
:xnio/io-threads io-threads
:xnio/worker-threads worker-threads
:xnio/dispatch executor})
handler (cond
(fn? handler) handler
(some? router) (wrap-router cfg router)

View file

@ -113,7 +113,7 @@
:host (cf/get :http-server-host)
:router (ig/ref :app.http/router)
:metrics (ig/ref :app.metrics/metrics)
:executors (ig/ref :app.worker/executors)
:executor (ig/ref [::default :app.worker/executor])
:io-threads (cf/get :http-server-io-threads)}
:app.http/router