cider

Ken Huang 2025-02-11T11:53:44.356599Z

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.

Ken Huang 2025-02-11T11:55:58.592399Z

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.

oyakushev 2025-02-11T12:01:20.160179Z

What does a lein ring server command do? I've never used that plugin, why do you need it?

Ken Huang 2025-02-11T12:03:06.613849Z

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.

Ken Huang 2025-02-11T12:05:35.492499Z

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?

oyakushev 2025-02-11T12:13:49.538299Z

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

oyakushev 2025-02-11T12:14:52.984739Z

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

oyakushev 2025-02-11T12:15:56.915359Z

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

oyakushev 2025-02-11T12:18:12.706899Z

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.

Ken Huang 2025-02-11T13:04:54.933199Z

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.

oyakushev 2025-02-11T13:05:54.313369Z

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.

oyakushev 2025-02-11T13:08:35.039769Z

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

Ken Huang 2025-02-11T13:26:58.074339Z

Yes, 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.

Evan Bernard 2025-02-11T20:18:44.941979Z

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

❤️ 1