lein-figwheel
lein-figwheel copied to clipboard
Proxy configuration
I’m working on a create-react-app equivalent for cljs/reagent with the goal of making it easier for JavaScript developers to get started with Clojure and Clojurescript.
One feature of CRA is a configuration in the package.json that allows the Webpack dev server (used for hot reloading) to serve as a reverse proxy.
https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#integrating-with-an-api-backend
Adding this feature to figwheel has been raised before (#554 #239).
I've thought it over a bit, read previous issues and the quick start and don't currently see how the same result can be achieved with existing features. I'm curious if you'd be willing to support a proxy configuration at this time. I'm happy to provide additional reasons or example use cases that I can't figure out how to solve without this feature if that would help.
Thanks!
So this is more than likely possible, with the ring middleware mentioned in #554 i.e "https://github.com/tailrecursion/ring-proxy"
as you can provide a :ring-handler
to figwheel and it should just work (and you can compose ring handlers from ring middleware)
But the recommended way of working with figwheel is to create a separate server than the figwheel server. Think of the figwheel server as a communication only websocket server.
All of your assets including compiled ClojureScript are served by the webserver of your design. If you want it to also proxy a backend as well it should be no problem.
Thanks for your feedback. I’ll try it and report back. 😊
@bhauman Thought you might want an example for this so I pushed https://github.com/alex-dixon/lein-figwheel/commit/216e7d9d93d9cdb23c2ccebbc20b7716f4181391.
Unfortunately I haven't been able to get it working. Any help would be appreciated.
The branch uses tailrecursion's ring proxy version 1.0.0-SNAPSHOT. The latest 3.0.0-SNAPSHOT isn't on Clojars. There's quite a few forks of it, including https://github.com/puppetlabs/ring-middleware. I tried that as well and no luck...it seems tailored to their use case but I'm not sure how much.
I've also tried the example here: https://blog.markhepburn.com/2017/06/12/quickie-using-figwheel-and-leiningen-as-a-proxy-server-for-fun-and-profit
Used the same package versions that are linked to with tailrecursion/ring-proxy 2.0.0-SNAPSHOT and still get errors. Seem to be coming from some of its dependencies.
Trying to ask for recommendations on a ring proxy middleware on clojurians slack.
@alex-dixon In case you appreciate the input, I recently made Figwheel work with my local nginx setup, for among other things getting https green bar.
I don't think nginx+figwheel is a usual setup, but it's certainly possible thanks to options such as :websocket-url
which let us point anywhere.
nginx being the reverse proxy par excellence, choosing that could make your project a bit neater, and also relieve figwheel from feature bloat.
Will share my setup when I have the chance!
@vemv I'm now looking into using a reverse proxy to serve assets produced by figwheel main + our app running in a boot process. Adding the output of figwheel to the boot process causes problems, that's why I probably prefer a reverse proxy solution.
Will share my setup when I have the chance!
Looking forward to that!
Unfortunately that one nginx.conf got totally lost. Only a few months later I started version-controlling anything and everything ;p
@vemv :) Any suggestions how to do this in 2020 with figwheel.main? Still nginx I guess?
I also guess so :) haven't played much with figwheel.main.
Anyway, for a websocket server I'd pick whatever my team is using in production for websockets. That way I can reuse some knowledge and possibly some moving parts.