Permalink
Browse files

Turn home-page into a function over the path that’s being rendered. A…

…lso re-name it render-app.
  • Loading branch information...
1 parent e147a5c commit e7273cfe45f69ebeb44cc9494883477aef28c8da @pupeno pupeno committed Sep 8, 2015
Showing with 20 additions and 15 deletions.
  1. +20 −15 src/clj/projectx/handler.clj
@@ -8,24 +8,29 @@
[ring.middleware.reload :refer [wrap-reload]]
[environ.core :refer [env]]))
-(def home-page
+(defn render-app [path]
(html
- [:html
- [:head
- [:meta {:charset "utf-8"}]
- [:meta {:name "viewport"
- :content "width=device-width, initial-scale=1"}]
- (include-css (if (env :dev) "css/site.css" "css/site.min.css"))]
- [:body
- [:div#app
- [:h3 "ClojureScript has not been compiled!"]
- [:p "please run "
- [:b "lein figwheel"]
- " in order to start the compiler"]]
- (include-js "js/app.js")]]))
+ [:html
+ [:head
+ [:meta {:charset "utf-8"}]
+ [:meta {:name "viewport"
+ :content "width=device-width, initial-scale=1"}]
+ (include-css (if (env :dev) "css/site.css" "css/site.min.css"))]
+ [:body
+ [:div#app
+ [:h3 "ClojureScript has not been compiled!"]
+ [:p "please run "
+ [:b "lein figwheel"]
+ " in order to start the compiler"]]
+ (include-js "js/app.js")]]))
+
+(defn- path [request]
+ (str (:uri request) ; Build the path the same way ring.util.request/request-url does it: https://github.com/ring-clojure/ring/blob/1.4.0/ring-core/src/ring/util/request.clj#L5
+ (if-let [query (:query-string request)]
+ (str "?" query))))
(defroutes routes
- (GET "/" [] home-page)
+ (GET "*" request (render-app (path request)))
(resources "/")
(not-found "Not Found"))

0 comments on commit e7273cf

Please sign in to comment.