Skip to content

Instantly share code, notes, and snippets.

@dharrigan
Created December 15, 2022 13:37
Show Gist options
  • Save dharrigan/0de573b78ea5d7c151be58cc727a9569 to your computer and use it in GitHub Desktop.
Save dharrigan/0de573b78ea5d7c151be58cc727a9569 to your computer and use it in GitHub Desktop.
(defn ^:private static-ring-handler
[app-config]
(ring/ring-handler (router)
(ring/routes
(ring/create-resource-handler {:path "/" :not-found-handler general-handler/not-found})
(ring/create-default-handler))))
(defn ^:private repl-friendly-ring-handler
[app-config]
(fn [request]
((static-ring-handler app-config) request)))
;; PUBLIC FUNCTIONS AND DEFINITIONS ↓
;; DONUT LIFECYCLE FUNCTIONS ↓
(defn start
[{{:keys [environment jetty]} :runtime-config :as app-config}]
(jetty/run-jetty
(if (contains? #{:local :development} environment)
(do
(log/infof "Using reloadable ring handler for handling requests as the environment is '%s'." (name environment))
(repl-friendly-ring-handler app-config))
(do
(log/infof "Using static ring handler for handling requests as the environment is '%s'." (name environment))
(static-ring-handler app-config)))
(merge jetty {:allow-null-path-info true
:send-server-version? false
:send-date-header? false
:join? false}))) ;; false so that we can stop it at the repl!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment