Skip to content

Commit

Permalink
Remove unused functions and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Nov 15, 2024
1 parent f846fa7 commit b611dcc
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 107 deletions.
3 changes: 0 additions & 3 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
[org.duct-framework/logger "0.4.0"]
[org.duct-framework/server.http.jetty "0.3.0"]
[org.duct-framework/router.reitit "0.2.0"]
[compojure "1.7.1"]
[integrant "0.13.1"]
[metosin/jsonista "0.3.12"]
[metosin/muuntaja "0.6.10"]
[org.slf4j/slf4j-nop "2.0.16"]
[org.webjars/normalize.css "5.0.0"]
[ring/ring-core "1.13.0"]
Expand Down
8 changes: 0 additions & 8 deletions src/duct/handler/root.clj

This file was deleted.

45 changes: 0 additions & 45 deletions src/duct/middleware/web.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
(ns duct.middleware.web
(:require [duct.logger :as logger]
[integrant.core :as ig]
[muuntaja.core :as mc]
[muuntaja.middleware :as mm]
[ring.middleware.defaults :refer [wrap-defaults]]
[ring.middleware.stacktrace :refer [wrap-stacktrace]]
[ring.middleware.webjars :refer [wrap-webjars]]
Expand Down Expand Up @@ -51,9 +49,6 @@
(defn- internal-error [response]
(response/status response 500))

(defn- not-found [response]
(response/status response 404))

(defn wrap-hide-errors
"Middleware that hides any uncaught exceptions behind a 500 'Internal Error'
response generated by an error handler. Intended for use in production when
Expand All @@ -69,32 +64,6 @@
(handler request respond (fn [_] (respond (internal-error (error-handler request)))))
(catch Throwable _ (respond (internal-error (error-handler request))))))))

(defn wrap-not-found
"Middleware that returns a 404 'Not Found' response from an error handler if
the base handler returns nil."
[handler error-handler]
(fn
([request]
(or (handler request) (not-found (error-handler request))))
([request respond raise]
(handler request #(respond (or % (not-found (error-handler request)))) raise))))

(defn- route-aliases-request [request aliases]
(if-let [alias (aliases (:uri request))]
(assoc request :uri alias)
request))

(defn wrap-route-aliases
"Middleware that takes a map of URI aliases. If the URI of the request matches
a URI in the map's keys, the URI is changed to the value corresponding to that
key."
[handler aliases]
(fn
([request]
(handler (route-aliases-request request aliases)))
([request respond raise]
(handler (route-aliases-request request aliases) respond raise))))

(defmethod ig/init-key ::log-requests
[_ {:keys [logger options]}]
#(wrap-log-requests % logger (dissoc options :logger)))
Expand All @@ -105,12 +74,6 @@
(defmethod ig/init-key ::hide-errors [_ {:keys [error-handler]}]
#(wrap-hide-errors % error-handler))

(defmethod ig/init-key ::not-found [_ {:keys [error-handler]}]
#(wrap-not-found % error-handler))

(defmethod ig/init-key ::route-aliases [_ aliases]
#(wrap-route-aliases % aliases))

(defmethod ig/init-key ::defaults [_ defaults]
#(wrap-defaults % defaults))

Expand All @@ -119,11 +82,3 @@

(defmethod ig/init-key ::stacktrace [_ options]
#(wrap-stacktrace % options))

(defn- deep-merge [a b]
(if (and (map? a) (map? b))
(merge-with deep-merge a b)
b))

(defmethod ig/init-key ::format [_ options]
#(mm/wrap-format % (deep-merge mc/default-options options)))
6 changes: 0 additions & 6 deletions src/duct/router/cascading.clj

This file was deleted.

13 changes: 0 additions & 13 deletions test/duct/handler/root_test.clj

This file was deleted.

32 changes: 0 additions & 32 deletions test/duct/middleware/web_test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns duct.middleware.web-test
(:require [clojure.test :refer :all]
[compojure.core :as compojure]
[duct.logger :as logger]
[duct.middleware.web :refer :all]
[integrant.core :as ig]
Expand Down Expand Up @@ -81,34 +80,3 @@
(handler (mock/request :get "/") respond raise)
(is (not (realized? raise)))
(is (= @respond response))))))

(deftest test-wrap-not-found
(let [err-handler (make-error-handler "Not Found")
response {:status 404, :headers {}, :body "Not Found"}]
(testing "synchronous"
(let [handler (wrap-not-found (constantly nil) err-handler)]
(is (= (handler (mock/request :get "/")) response))))

(testing "asynchronous"
(let [handler (wrap-not-found (fn [_ respond _] (respond nil)) err-handler)
respond (promise)
raise (promise)]
(handler (mock/request :get "/") respond raise)
(is (not (realized? raise)))
(is (= @respond response))))))

(deftest test-wrap-route-aliases
(let [response {:status 200
:headers {"Content-Type" "text/html; charset=utf-8"}
:body "foo"}
handler (-> (compojure/GET "/index.html" [] "foo")
(wrap-route-aliases {"/" "/index.html"}))]
(testing "synchronous"
(is (= (handler (mock/request :get "/")) response)))

(testing "asynchronous"
(let [respond (promise)
raise (promise)]
(handler (mock/request :get "/") respond raise)
(is (not (realized? raise)))
(is (= @respond response))))))

0 comments on commit b611dcc

Please sign in to comment.