Anyone develops lein ring app here? How would you start a repl and jack into it? =lein ring server= will start the web server and nrepl if configured, but cider doesn’t function well presumably since cider-repl middleware aren’t loaded.
Right now I just started another repl using M-x cider-jack-in-clj, which will run a =lein repl= command with middleware loaded, it worked but it was silly.
What does a lein ring server command do? I've never used that plugin, why do you need it?
https://github.com/weavejester/lein-ring Lein-Ring is a Leiningen plugin that automates common Ring tasks. It provides commands to start a development web server, and to turn a Ring handler into a standard war file.
I used it because I just found it the other day and it worked, currently mainly to bing up a dev server. How do you do that then?
In all projects where I have some sort of a web server, I start it manually from the REPL, be it via a direct function invocation (`(start-server something)`) or as a part of a Component/Mount system. I don't know if lein ring server does anything extra – it seems to have some hot-reloading parts? – but I'm not sure if you need/use that. You may take a look what the plugin does exactly here https://github.com/weavejester/lein-ring/blob/master/src/leiningen/ring/server.clj#L72-L91 and recreate that call in your normal REPL (except for the eval-in-project bits, you won't need that in the REPL).
I'm sure there are plenty of examples how to do it, and you may consult an LLM too. Here's the example from a recent web app that I made: https://github.com/clojure-goes-fast/flamebin/blob/master/src/flamebin/web.clj#L136-L142
This one uses Mount. If it didn't, then I just call the (server/run-server ...) manually after I compile all the code inside the REPL
Alternatively, you could try to feed the correct middleware to the nREPL server that the lein ring server starts, but that feels very upside-down to me.
Thanks! Originally I started with deps.edn cuz it’s built in, and started the web server manually. I felt like it’s a bit tedious and I had no idea how to package the build for deployment, so I switched to use lein.
Sure you can keep using Lein and the lein-ring plugin for other tasks like building, but it's better to start the REPL in a uniform way that doesn't involve the plugin.
A common pattern to reduce manual work is to have a src/user.clj file where you would have a function called e.g. dev . Inside the function you would require all the necessary namespaces and then launch the web server (and possibly other stateful parts – DB pools, etc.). Then, it becomes a matter of doing:
user=> (dev)
the moment the REPL starts. Just a single extra action but much more flexibility than having a plugin do it.
Example: https://github.com/clojure-goes-fast/flamebin/blob/master/dev/user.cljYes, I saw that some projects put dev stuff in a separate file, it's just that there are too many things to learn at the moment, so lein may be more suitable for me currently.
I don’t know if it really applies here, but one thing I used to do when working with jetty apps and the repl was I would, from the repl, start the server and bind the result to some symbol via def. that would free up the repl while still allowing me to start/stop the jetty server
IIRC, I don’t know that stopping/starting always worked - I seem to recall having to occasionally restart the repl