       ;; since they're not compatible with this middleware
       ((if (:websocket? request) handler wrapped) request))))
 
+(defn wrap-base-url
+  "Add base URL to Ring request."
+  [handler]
+  (fn [request]
+    (let [base-url (-> request
+                       request-url
+                       url
+                       (dissoc :query :path)
+                       (assoc :path (:context request))
+                       map->URL)]
+      (handler (assoc request :base-url base-url)))))
+
 (defn wrap-base [handler]
   (-> ((:middleware defaults) handler)
       wrap-webjars

            (assoc-in [:security :anti-forgery] false)
            (assoc-in [:session :store] (ttl-memory-store (* 60 30)))))
      wrap-context
      wrap-internal-error))

            [ring.middleware.webjars :refer [wrap-webjars]]
            [ring.middleware.format :refer [wrap-restful-format]]
            [ring-ttl-session.core :refer [ttl-memory-store]]
            [ring.middleware.defaults :refer [site-defaults wrap-defaults]]
            [ring.util.request :refer [request-url]]
            [cemerick.url :refer [map->URL url]])
  (:import [javax.servlet ServletContext]))

(defn wrap-context [handler]
