Skip to content

Instantly share code, notes, and snippets.

@piranha
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piranha/046f7a31049957283e1f to your computer and use it in GitHub Desktop.
Save piranha/046f7a31049957283e1f to your computer and use it in GitHub Desktop.
(ns mailers.main
(:gen-class)
(:require [com.stuartsierra.component :as c]
[aleph.http :as aleph]
[manifold.stream :as mani]
[ring.util.response :as response]
[ring.middleware.file-info :only [wrap-file-info]]
[ring.middleware.resource :refer [wrap-resource]]))
(defn handle-message [s msg]
(mani/put! s msg))
(defn root-handler [req]
(if-let [s @(aleph/websocket-connection req)]
(mani/consume (partial handle-message s) s)
(resource/resource-response "index.html" {:root "public"})))
(defn ring-app []
(-> (aleph/wrap-aleph-handler root-handler)
(wrap-resource "public")
wrap-file-info))
(defrecord WebserverComponent []
c/Lifecycle
(start [c]
(-> (aleph/wrap-ring-handler ring-app)
(aleph/start-server {:port port})
((partial assoc c :web))))
(stop [c]
(.close (:web c))
(dissoc c :web)))
(defn -main [& args]
(println args))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment