       (.close conn))))
 
 (defn- server-loop
-  [root server-socket]
+  [opts server-socket]
   (let [conn (.accept server-socket)]
     (do (.setKeepAlive conn true)
-        (future (handle-connection root conn))
-        (recur root server-socket))))
+        (future (handle-connection opts conn))
+        (recur opts server-socket))))
 
 (defn start-server
   "Start the server on the specified port."
-  [root port]
-  (do (println "Starting Server on Port:" port)
-      (let [ss (ServerSocket. port)]
-        (future (server-loop root ss))
-        (swap! server-state (fn [old] {:socket ss :port port})))))
+  [opts]
+  (do (println "Starting Server on Port:" (:port opts))
+      (let [ss (ServerSocket. (:port opts))]
+        (future (server-loop opts ss))
+        (swap! server-state (fn [old] {:socket ss :port (:port opts)})))))
 
 (defn stop-server
   []

      {:type :return
       :value ret})))

(defrecord BrowserEvaluator [root port]
  IEvaluator
  (-setup [this]
    (comp/with-core-cljs (start-server root port)))
  (-evaluate [this line js]
    (browser-eval js))
  (-put [this k v]

    (do (stop-server)
        (reset! server-state {}))))

(defn repl-env [& {:keys [port root] :as opts}]
  (let [opts (merge {:port 9000 :root "" :main "main.js" :goog-base "out/goog/base.js"} opts)]
    (BrowserEvaluator. opts)))

(comment
  
  (require '[cljs.repl :as repl])
  (require '[cljs.repl.browser :as browser])
  (def env (browser/repl-env :main "out/repl.js"))
  (repl/repl env)
  ;; simulate the browser with curl
  ;; curl -v -d "ready" http://127.0.0.1:9000
