Drop compojure dependency

It was hardly used and makes control flow, reloaded workflow more difficult.
This commit is contained in:
Nicholas Kariniemi 2014-10-12 12:25:15 +03:00
parent 58373496f0
commit ec27d58e31
2 changed files with 23 additions and 21 deletions

View file

@ -8,7 +8,6 @@
[org.clojure/core.async "0.1.346.0-17112a-alpha"] [org.clojure/core.async "0.1.346.0-17112a-alpha"]
[om "0.7.3"] [om "0.7.3"]
[http-kit "2.1.18"] [http-kit "2.1.18"]
[compojure "1.1.8"]
[ring/ring-core "1.3.0" :exclusions [org.clojure/tools.reader]] [ring/ring-core "1.3.0" :exclusions [org.clojure/tools.reader]]
[ring/ring-devel "1.3.0" :exclusions [org.clojure/tools.reader]] [ring/ring-devel "1.3.0" :exclusions [org.clojure/tools.reader]]
[hiccup "1.0.5"] [hiccup "1.0.5"]

View file

@ -4,10 +4,8 @@
[grub.test.integration.core :as integration-test] [grub.test.integration.core :as integration-test]
[grub.state :as state] [grub.state :as state]
[ring.middleware.file :as file] [ring.middleware.file :as file]
[ring.middleware.content-type :as content-type]
[ring.util.response :as resp] [ring.util.response :as resp]
[compojure.core :refer [defroutes GET POST]]
[compojure.handler :as handler]
[compojure.route :as route]
[org.httpkit.server :as httpkit] [org.httpkit.server :as httpkit]
[clojure.core.async :as a :refer [<! >! chan go]] [clojure.core.async :as a :refer [<! >! chan go]]
[hiccup [hiccup
@ -42,26 +40,31 @@
(def index-page (atom dev-index-page)) (def index-page (atom dev-index-page))
(defn websocket-handler [request] (def default-port 3000)
(when (:websocket? request)
(defn handle-websocket [handler]
(fn [{:keys [websocket?] :as request}]
(if websocket?
(httpkit/with-channel request ws-channel (httpkit/with-channel request ws-channel
(let [to-client (chan) (let [to-client (chan)
from-client (chan)] from-client (chan)]
(ws/add-connected-client! ws-channel to-client from-client) (ws/add-connected-client! ws-channel to-client from-client)
(state/sync-new-client! to-client from-client))))) (state/sync-new-client! to-client from-client)))
(handler request))))
(defroutes routes (defn handle-root [handler]
(GET "/" [] websocket-handler) (fn [{:keys [uri] :as request}]
(GET "/" [] @index-page) (if (= uri "/")
(GET "*/src/cljs/grub/:file" [file] (resp/file-response file {:root "src/cljs/grub"})) (resp/response @index-page)
(GET "/js/public/js/:file" [file] (resp/redirect (str "/js/" file))) (handler request))))
(route/files "/")
(route/not-found "<p>Page not found.</p>"))
(def default-port 3000)
(defn start-server [port] (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 [] (defn run-integration-test []
(let [stop-server (start-server integration-test/server-port)] (let [stop-server (start-server integration-test/server-port)]