From ec27d58e3118022028c156fcad3b2781ff2da6a1 Mon Sep 17 00:00:00 2001 From: Nicholas Kariniemi Date: Sun, 12 Oct 2014 12:25:15 +0300 Subject: [PATCH] Drop compojure dependency It was hardly used and makes control flow, reloaded workflow more difficult. --- project.clj | 1 - src/clj/grub/core.clj | 43 +++++++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/project.clj b/project.clj index 8dc8786..442d3bc 100644 --- a/project.clj +++ b/project.clj @@ -8,7 +8,6 @@ [org.clojure/core.async "0.1.346.0-17112a-alpha"] [om "0.7.3"] [http-kit "2.1.18"] - [compojure "1.1.8"] [ring/ring-core "1.3.0" :exclusions [org.clojure/tools.reader]] [ring/ring-devel "1.3.0" :exclusions [org.clojure/tools.reader]] [hiccup "1.0.5"] diff --git a/src/clj/grub/core.clj b/src/clj/grub/core.clj index 7b23b5f..bf2c9cf 100644 --- a/src/clj/grub/core.clj +++ b/src/clj/grub/core.clj @@ -4,10 +4,8 @@ [grub.test.integration.core :as integration-test] [grub.state :as state] [ring.middleware.file :as file] + [ring.middleware.content-type :as content-type] [ring.util.response :as resp] - [compojure.core :refer [defroutes GET POST]] - [compojure.handler :as handler] - [compojure.route :as route] [org.httpkit.server :as httpkit] [clojure.core.async :as a :refer [! chan go]] [hiccup @@ -42,26 +40,31 @@ (def index-page (atom dev-index-page)) -(defn websocket-handler [request] - (when (:websocket? request) - (httpkit/with-channel request ws-channel - (let [to-client (chan) - from-client (chan)] - (ws/add-connected-client! ws-channel to-client from-client) - (state/sync-new-client! to-client from-client))))) - -(defroutes routes - (GET "/" [] websocket-handler) - (GET "/" [] @index-page) - (GET "*/src/cljs/grub/:file" [file] (resp/file-response file {:root "src/cljs/grub"})) - (GET "/js/public/js/:file" [file] (resp/redirect (str "/js/" file))) - (route/files "/") - (route/not-found "

Page not found.

")) - (def default-port 3000) +(defn handle-websocket [handler] + (fn [{:keys [websocket?] :as request}] + (if websocket? + (httpkit/with-channel request ws-channel + (let [to-client (chan) + from-client (chan)] + (ws/add-connected-client! ws-channel to-client from-client) + (state/sync-new-client! to-client from-client))) + (handler request)))) + +(defn handle-root [handler] + (fn [{:keys [uri] :as request}] + (if (= uri "/") + (resp/response @index-page) + (handler request)))) + (defn start-server [port] - (httpkit/run-server (handler/site routes) {:port port})) + (httpkit/run-server (-> (fn [req] "Not found") + (file/wrap-file "public") + (content-type/wrap-content-type) + (handle-root) + (handle-websocket)) + {:port port})) (defn run-integration-test [] (let [stop-server (start-server integration-test/server-port)]