Fork me on GitHub
#fulcro
<
2022-05-04
>
sheluchin17:05:16

If I start my server with clojure -A:dev:xtdb -M -m com.example.components.server, how do I connect to that same REPL? For example, if I want to inspect the (mount/running-states).

dvingo18:05:32

here's how to start one with mount:

(ns co.app.nrepl-server
    (:require
      [co.app.server.config :refer [config]]
      [mount.core :refer [defstate]]
      [nrepl.server :refer [start-server stop-server]]))

  (defstate nrepl-server
    :start
    (let [{keys [port]} (::config config)]
      (start-server :port port))

    :stop
    (stop-server nrepl-server))
(and of course add the dep and include this ns in your server entry)

gratitude-thank-you 1
Hukka18:05:49

Or use the socket repl, so you don't need nrepl if you wouldn't use it otherwise

Hukka18:05:05

I would use clj -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.9.0"} cider/cider-nrepl {:mvn/version "0.28.3"}}}' -m nrepl.cmdline --middleware '["cider.nrepl/cider-middleware"]' --interactive if nrepl is needed sometimes, instead of adding code for it.

sheluchin18:05:36

@U8ZQ1J1RR so first I would launch my server and then use that command to access the nrepl? I'm doing that and it still doesn't seem to be the same REPL as my running server.

$ clj -A:dev:xtdb -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.9.0"} cider/cider-nrepl {:mvn/version "0.28.3"}}}'  -m nrepl.cmdline  --middleware '["cider.nrep l/cider-middleware"]' --interactive
WARNING: Implicit use of clojure.main with options is deprecated, use -M
nREPL server started on port 42755 on host localhost - 
nREPL 0.9.0
Clojure 1.10.3
OpenJDK 64-Bit Server VM 11.0.15+10-Ubuntu-0ubuntu0.20.04.1
Interrupt: Control+C
Exit:      Control+D or (exit) or (quit)
user=> (use '[mount.core :as mount])
nil
user=> (use '[com.example.components.server :as server])
2022-05-04T18:46:31.120Z ubuntu-focal DEBUG [com.fulcrologic.rad.blob:197] - Wrapping persist-images with image keys #{}
nil
user=> (mount/running-states)
#{}
Or do you mean that I should add that to my current launch command when starting the server?

Hukka19:05:16

Yes, you cannot bolt on a repl on a different process. But you can launch it purely on command line without making code changes

sheluchin22:05:05

Okay, that's a useful option indeed if I'm just using the REPL occasionally to debug stuff. Thank you for the tip. I wonder, is using the REPL a common thing in production?

Hukka04:05:56

I don't think so, but that's just what I hear in the local bubble. Sean Corfield is a big proponent of repl in production, and I think they have the socket repl always running

sheluchin12:05:44

This handy practicalli repo has an https://github.com/practicalli/clojure-deps-edn/blob/live/deps.edn#L107-L114= defined for exactly what you suggested @U8ZQ1J1RR. Along with a few other useful ones that are related. Posting here for reference.

Hukka12:05:18

Yeah, some people like to have a global alias. I just dig it from shell history ๐Ÿ™‚

1
tony.kay18:05:56

Fulcro (nor itโ€™s templates) do not, by default, install an nREPL server.