summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2012-04-09 20:32:01 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2012-04-09 20:32:01 +0200
commit24a8c82305b81c11d26589dc82224640ab29fc35 (patch)
tree5cde156c4312a5ef4fb4887c348587911331b00a
parentf7eb36d782508cbf3cc73e1f05630776d4a207bd (diff)
Migrate to noir-async.
-rw-r--r--project.clj2
-rw-r--r--src/mulk/benki/main.clj43
2 files changed, 40 insertions, 5 deletions
diff --git a/project.clj b/project.clj
index a6e2048..4d8e35e 100644
--- a/project.clj
+++ b/project.clj
@@ -24,6 +24,8 @@
[noir "1.2.1"]
[hiccup "0.3.7"]
[cssgen "0.2.5"]
+ [aleph "0.2.1-beta2"]
+ [noir-async "1.0.0-SNAPSHOT"]
;; Relational database access
[clojureql "1.0.3"]
diff --git a/src/mulk/benki/main.clj b/src/mulk/benki/main.clj
index a5e7b31..edf0583 100644
--- a/src/mulk/benki/main.clj
+++ b/src/mulk/benki/main.clj
@@ -9,7 +9,11 @@
[ring.middleware.file]
[noir.session :as session]
[noir.request :as request]
- [clojure.java.jdbc :as sql])
+ [clojure.java.jdbc :as sql]
+ [lamina.core :as lamina]
+ [aleph.http :as ahttp]
+ [aleph.formats :as aformats]
+ [ring.util.codec :as codec])
(:import [java.math BigDecimal BigInteger]))
@@ -54,17 +58,46 @@
(session/get :user))]
(handler request))))
+(defn wrap-extension-mimetype [handler]
+ (fn [request]
+ (let [uri (codec/url-decode (:uri request))
+ response (handler request)
+ extension (second (re-find #"\.([\w]*)($|\?)" uri))
+ exttype ({"txt" "text/plain"
+ "css" "text/css"
+ "js" "text/javascript"
+ "html" "text/html"
+ "jpg" "image/jpeg"
+ "gif" "image/gif"
+ "png" "image/png"}
+ extension)]
+ (if (and (nil? (get-in response [:headers "Content-Type"]))
+ exttype)
+ (assoc-in response [:headers "Content-Type"] exttype)
+ response))))
+
(do-once ::init
(noir.server/add-middleware #(wrap-utf-8 %))
(noir.server/add-middleware #(wrap-base-uri %))
(noir.server/add-middleware #(wrap-auth-token %))
(noir.server/add-middleware #(wrap-cache-control %))
- (noir.server/add-middleware #(ring.middleware.file/wrap-file % "static")))
+ (noir.server/add-middleware #(ring.middleware.file/wrap-file % "static"))
+ (noir.server/add-middleware #(wrap-extension-mimetype %)))
+
+(defonce server (atom nil))
-(defonce server (doto (Thread. #(noir.server/start (:web-port @benki-config)))
- (.setDaemon true)
- (.start)))
+(defn run-server []
+ (let [mode (or (:mode @benki-config) :production)
+ noir-handler (noir.server/gen-handler {:mode mode})]
+ (reset! server
+ (ahttp/start-http-server (ahttp/wrap-ring-handler noir-handler)
+ {:port (:web-port @benki-config)
+ :websocket true}))))
+(do-once ::start
+ (doto (Thread. run-server)
+ (.setDaemon true)
+ (.start)))
(defn -main [& args]
(loop []