mirror of
https://github.com/penpot/penpot.git
synced 2025-05-06 21:25:53 +02:00
📎 Improve api ergonomy of http server module
This commit is contained in:
parent
52029f83ef
commit
cf4f999b6a
2 changed files with 12 additions and 9 deletions
|
@ -35,8 +35,8 @@
|
||||||
(s/def ::port ::us/integer)
|
(s/def ::port ::us/integer)
|
||||||
(s/def ::host ::us/string)
|
(s/def ::host ::us/string)
|
||||||
(s/def ::name ::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 ::io-threads ::cf/http-server-io-threads)
|
||||||
|
(s/def ::worker-threads integer?)
|
||||||
|
|
||||||
(defmethod ig/prep-key ::server
|
(defmethod ig/prep-key ::server
|
||||||
[_ cfg]
|
[_ cfg]
|
||||||
|
@ -46,18 +46,21 @@
|
||||||
(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 ::executors]
|
(s/keys :req-un [::port ::host ::name]
|
||||||
:opt-un [::router ::handler ::io-threads]))
|
:opt-un [::router ::handler ::io-threads ::worker-threads ::wrk/executor]))
|
||||||
|
|
||||||
(defmethod ig/init-key ::server
|
(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"
|
(l/info :hint "starting http server"
|
||||||
:port port :host host :name name)
|
:port port :host host :name name)
|
||||||
|
|
||||||
(let [options {:http/port port
|
(let [options (d/without-nils
|
||||||
|
{:http/port port
|
||||||
:http/host host
|
:http/host host
|
||||||
:ring/async true
|
:ring/async true
|
||||||
:xnio/dispatch (:default executors)}
|
:xnio/io-threads io-threads
|
||||||
|
:xnio/worker-threads worker-threads
|
||||||
|
:xnio/dispatch executor})
|
||||||
handler (cond
|
handler (cond
|
||||||
(fn? handler) handler
|
(fn? handler) handler
|
||||||
(some? router) (wrap-router cfg router)
|
(some? router) (wrap-router cfg router)
|
||||||
|
|
|
@ -113,7 +113,7 @@
|
||||||
:host (cf/get :http-server-host)
|
:host (cf/get :http-server-host)
|
||||||
:router (ig/ref :app.http/router)
|
:router (ig/ref :app.http/router)
|
||||||
:metrics (ig/ref :app.metrics/metrics)
|
: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)}
|
:io-threads (cf/get :http-server-io-threads)}
|
||||||
|
|
||||||
:app.http/router
|
:app.http/router
|
||||||
|
|
Loading…
Add table
Reference in a new issue