lein-figwheel icon indicating copy to clipboard operation
lein-figwheel copied to clipboard

Proxy configuration

Open alex-dixon opened this issue 6 years ago • 9 comments

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!

alex-dixon avatar Dec 21 '17 16:12 alex-dixon

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.

bhauman avatar Dec 22 '17 01:12 bhauman

Thanks for your feedback. I’ll try it and report back. 😊

alex-dixon avatar Dec 22 '17 02:12 alex-dixon

@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.

alex-dixon avatar Dec 22 '17 17:12 alex-dixon

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 avatar Dec 27 '17 15:12 alex-dixon

@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 avatar Jan 07 '18 09:01 vemv

@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!

borkdude avatar Jul 20 '20 16:07 borkdude

Unfortunately that one nginx.conf got totally lost. Only a few months later I started version-controlling anything and everything ;p

vemv avatar Jul 20 '20 16:07 vemv

@vemv :) Any suggestions how to do this in 2020 with figwheel.main? Still nginx I guess?

borkdude avatar Jul 20 '20 16:07 borkdude

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.

vemv avatar Jul 20 '20 20:07 vemv