   (:require [org.httpkit.server :refer [run-server]]
             [compojure.route :refer [resources]]
             [compojure.core :refer [GET POST routes defroutes context]]
-            [ring.middleware.defaults :refer [wrap-defaults secure-site-defaults site-defaults]]
+            [ring.middleware.defaults :refer [wrap-defaults api-defaults secure-site-defaults site-defaults]]
             [ring.middleware.edn :refer [wrap-edn-params]]
             [clojure.string :as string]
             [clojure.tools.nrepl.server :as nrepl]

                                    :port 6379}})

(def app
  (->
    (wrap-defaults
      (routes
        resource-routes
        site-routes
        sync-routes)
      (-> site-defaults ; ssl stuff will be handled by nginx
          (assoc-in [:session :cookie-attrs :secure] (= (env :environment) "prod"))
          (assoc-in [:session :store] (carmine/carmine-store *redis-conf*
                                                             {:expiration-secs (* 60 60 24 7)
                                                              :key-prefix "lpchat"}))
          (assoc-in [:security :anti-forgery]
            {:read-token (fn [req] (-> req :params :csrf-token))})))
      wrap-edn-params))

(defonce server (atom nil))


    (let [fail {:status 400 :headers {"Content-Type" "text/plain"}}]
      (cond
        (string/blank? password) (assoc fail :body "Must provide a password")
        (not (invites/verify-hmac hmac (str now token invite_id email))) (assoc fail :body "Invalid HMAC")
        (string/blank? invite_id) (assoc fail :body "Invalid invitation ID")
        ; TODO: be smarter about this
        (not (#{"image/jpeg" "image/png"} (:content-type avatar))) (assoc fail :body "Invalid image")

        :else
        (let [invite (db/with-conn (db/get-invite (java.util.UUID/fromString invite_id)))]
