summaryrefslogtreecommitdiff
path: root/src
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 /src
parentf7eb36d782508cbf3cc73e1f05630776d4a207bd (diff)
Migrate to noir-async.
Diffstat (limited to 'src')
-rw-r--r--src/mulk/benki/main.clj43
1 files changed, 38 insertions, 5 deletions
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 []