-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added jetty adapter, fixed http-kit adapter key
- Loading branch information
Showing
6 changed files
with
63 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
libs/deps-template/resources/io/github/kit_clj/kit/versions.edn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{:paths ["src"] | ||
:deps {integrant/integrant {:mvn/version "0.9.0"} | ||
ring/ring-jetty-adapter {:mvn/version "1.12.2"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
(ns kit.edge.server.jetty | ||
(:require | ||
[integrant.core :as ig] | ||
[clojure.tools.logging :as log] | ||
[ring.adapter.jetty :as jetty])) | ||
|
||
(defn start [handler {:keys [host port] :as opts}] | ||
(try | ||
(log/info "starting HTTP server on port" port) | ||
(jetty/run-jetty | ||
handler | ||
(-> opts | ||
(assoc :join? false) | ||
(dissoc :handler :init))) | ||
(catch Throwable t | ||
(log/error t (str "server failed to start on" host "port" port)) | ||
(throw t)))) | ||
|
||
(defn stop [http-server] | ||
(let [result @(future (.stop http-server))] | ||
(log/info "HTTP server stopped") | ||
result)) | ||
|
||
(defmethod ig/expand-key :server/http | ||
[k config] | ||
{k (merge {:port 3000 | ||
:host "0.0.0.0"} | ||
config)}) | ||
|
||
(defmethod ig/init-key :server/http | ||
[_ opts] | ||
(let [handler (atom (delay (:handler opts)))] | ||
{:handler handler | ||
:server (start (fn [req] (@@handler req)) (dissoc opts :handler))})) | ||
|
||
(defmethod ig/halt-key! :server/http | ||
[_ {:keys [server]}] | ||
(stop server)) | ||
|
||
(defmethod ig/suspend-key! :server/http | ||
[_ {:keys [handler]}] | ||
(reset! handler (promise))) | ||
|
||
(defmethod ig/resume-key :server/http | ||
[k opts old-opts old-impl] | ||
(if (= (dissoc opts :handler) (dissoc old-opts :handler)) | ||
(do (deliver @(:handler old-impl) (:handler opts)) | ||
old-impl) | ||
(do (ig/halt-key! k old-impl) | ||
(ig/init-key k opts)))) |