bhauman / lein-figwheel

Figwheel builds your ClojureScript code and hot loads it into the browser as you are coding!
Eclipse Public License 1.0
2.88k stars 210 forks source link

Can't get remote reloading to work by any means #684

Closed IamCarbonMan closed 6 years ago

IamCarbonMan commented 6 years ago

I'm trying to setup lein-figwheel on an AWS dev box. I SSH into the development machine and connect to its public IP from my browser. But no matter what I try I get an error in the browser console: WebSocket connection to 'ws://localhost:3449/figwheel-ws/dev' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED. I've tried using :server-ip "<literal-ip-address>", :websocket-host :js-client-host, `:websocket-url "ws://<literal-ip-address/figwheel-ws/dev". None of these have any effect. Here's my project.clj:

(defproject tabletop "0.0.0"
  :description "Tabletop games in the browser"
  :url "https://github.com/IamCarbonMan/tabletop"
  :dependencies [[org.clojure/clojure "1.9.0"]
                 [org.clojure/clojurescript "1.9.946"]
                 [org.clojure/core.async "0.4.474"
                  :exclusions [org.clojure/tools.reader]]
                 [ring/ring-defaults "0.3.1"]
                 [compojure "1.6.1"]]
  :plugins [[lein-figwheel "0.5.15"]
            [lein-cljsbuild "1.1.7" :exclusions [[org.clojure/clojure]]]
            [lein-ring "0.12.4"]]
  :ring {:handler example.server-handler/app
         :init tabletop.server/init}
  :source-paths ["src"]
  :cljsbuild {:builds
              [{:id "dev"
                :source-paths ["src"]
                :figwheel {:on-jsload "tabletop.core/on-js-reload"
                           :websocket-url "ws://54.213.249.100:3449/figwheel-ws/dev"}
                :compiler {:main tabletop.core
                           :asset-path "js/compiled/out"
                           :output-to "resources/public/js/compiled/example.js"
                           :output-dir "resources/public/js/compiled/out"
                           :source-map-timestamp true
                           :preloads [devtools.preload]}}
               {:id "prod"
                :source-paths ["src"]
                :compiler {:output-to "resources/public/js/compiled/example.js"
                           :main tabletop.core
                           :optimizations :advanced
                           :pretty-print false}}]}
  :figwheel {:init     user/start-server
             :destroy  user/stop-server
             :css-dirs ["resources/public/css"]}
  :aliases {"package" ["do" "clean"
                       ["cljsbuild" "once" "prod"]
                       ["ring" "uberjar"]]}
  :profiles {:dev {:dependencies [[binaryage/devtools "0.9.10"]
                                  [com.cemerick/piggieback "0.2.1"]
                                  [ring-server "0.5.0"]]
                   :clean-targets ^{:protect false} ["resources/public/js/compiled" "target"]
                   :source-paths ["src" "dev"]
                   :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}}})
bhauman commented 6 years ago

This sounds like a caching problem of some kind, because :websocket-url does indeed work.

Remember to do a lein clean. Also, you may want to try 0.5.16-SNAPSHOT as it has improved the caching situation a bit.

IamCarbonMan commented 6 years ago

lein clean doesn't seem to change anything. Nor does using lein-figwheel 0.5.16-SNAPSHOT. I've removed and reinstalled the whole project and tested each option again, so it's definitely not a caching problem.

IamCarbonMan commented 6 years ago

Well, I'm an idiot. The issue was the line: :init tabletop.server/init. I haven't implemented the init function yet, removing that line fixed it, not sure why though. However, I'm now getting: socket.cljs?rel=1524715185107:71 WebSocket connection to 'ws://54.213.249.100:3449/figwheel-ws/dev/dev' failed: Error during WebSocket handshake: Unexpected response code: 404. Changing :websocket-url to "ws://${ip-address}/figwheel-ws" or using :websocket-host :js-client-host have the same error.

bhauman commented 6 years ago

ws://54.213.249.100:3449/figwheel-ws/dev/dev is wrong it should be ws://54.213.249.100:3449/figwheel-ws/dev

Use: :websocket-url ws://54.213.249.100:3449/figwheel-ws

IamCarbonMan commented 6 years ago

I did just that, still didn't work. I'm nor sure what I changed to make it work at this point, but unless someone else has the same issue this can be closed.

anghene commented 4 years ago

I encountered the same issue, figwheel just appends the name of my build to the websocket-url. i described more here: https://github.com/bhauman/lein-figwheel/issues/683#issuecomment-561220278