plexus / chestnut

Application template for Clojure + ClojureScript web apps
Eclipse Public License 1.0
1.32k stars 99 forks source link

Figwheel as app server #204

Closed malfario closed 7 years ago

malfario commented 7 years ago

Hi!

The README generated for my project with Chestnut 0.15.1 states:

Figwheel's server will also act as your app server, so requests are correctly forwarded to the http-handler you define.

However, Compojure routes defined in project.routes/home-routes are not accessible through Figwheel's server at localhost:3449, but through the Jetty instance running on localhost:10555.

Is there a way to expose new routes through Figwheel's HTTP server?

Thanks in advance!

plexus commented 7 years ago

Thanks for reporting this, we'll likely change this back because the different ports are confusing people. In the meanwhile this should be removed from the README. I don't have time for it at the moment though but it would be great if someone could submit a PR.

What you can do as a workaround is put this in user.clj

(def figwheel-http-handler
  (constantly {:status 301
               :headers {"Location" "http://localhost:10555"}}))

And in project.clj

  :figwheel {
             ;;;;; snip
             :ring-handler user/figwheel-http-handler
           }

If you really want to also serve up things through Figwheel you can set up a handler that reaches into reloaded.repl/system and finds the current system's handler from there.

(defn figwheel-http-handler  [req]
  ((get-in reloaded.repl/system [:handler :handler]) req))
malfario commented 7 years ago

Thank you so much, your last suggestion allows me to write clean cljs-ajax queries while being CORS friendly:

(GET "/tickets") vs (GET "http://localhost:10555/tickets")

Cheers!

malfario commented 7 years ago

Closed by 3a5a95c