                          java.io.PushbackReader.)]
     (clojure.edn/read reader)))
 
+(defn wrap-authentication [app userauth port]
+  (if userauth
+    (auth/wrap-google-authentication
+      app
+      (str (local-url port) "/") ; XXX local-url? Is this correct?
+      "/code"
+      (auth/load-users "users.txt")
+      (load-edn-from "auth.config"))
+    app))
+
 ; XXX add ring jsonp?
-(defn- get-app [docroot db loader port]
+(defn- get-app [docroot db loader port userauth]
   (-> cavm.views.datasets/routes
-      (auth/wrap-google-authentication
-       (str (local-url port) "/")
-       "/code"
-       (auth/load-users "users.txt")
-       (load-edn-from "auth.config"))
+      (wrap-authentication userauth port)
       (wrap-trace :header :ui)
       (attr-middleware :docroot docroot)
       (attr-middleware :db db)

        gui (:gui options)
        certfile (:certfile options)
        keyfile (:keyfile options)
        keystore (if keyfile
                   {:keystore (ssl/key-store keyfile certfile)
                    :password (String. ^chars ssl/key-store-password)}

                              (println "Failed to start gui. Logging error.")
                              (error "Failed to start gui." ex)))))
                      (when (:serve options)
                        (serv (get-app docroot db loader port userauth) host port keystore))))))
        (catch Exception ex
          ; XXX maybe should enable ERROR logging to console, instead of this.
          (binding [*out* *err*]
