Fork me on GitHub
#fulcro
<
2021-02-01
>
AJ Snow00:02:13

for my fulcro application, my understanding is i'll need a server of some kind set up. the fulcro template uses postgres, but for now I just want to get a running production instance without adding on a database. I see in the book that http-kit is mentioned, would that be an appropriate tool for my use case?

tony.kay04:02:45

Fulcro supports full stack operation, but it does not require a server. “long term storage” is typically modeled through the concept of a “remote”, which is usually http or websockets to some kind of server, often Ring-based. You can easily use a client-side storage mechanism (e.g. Datascript serialized into LocalStorage?) or even a “mock” server that does not persist over page reloads to model the server. A remote is just a map with a :transmit! key that supports a lambda to do the operations of “remote” communication, but that is a complete abstraction. The book, for example, does all of it’s full-stack demonstrations in-browser through such a “mock” remote.

AJ Snow05:02:38

well the main thing is my clj and cljc files for my revolvers. that sounds like something that might be worth accomplishing if it makes the project simpler, but I'm not sure if it would. I've never tried making a mock server before. Is that worth pursuing for a small project?

Jakub Holý (HolyJak)09:02:04

> the main thing is my clj and cljc files for my revolvers I do not understand what the problem is. > making a mock server You don't need that. For example start with fulcro template but replace Postgres with a simple atom holding a map. That will be your (not-persistent) DB. Or do what the Book does and run this and pathom in the browser, if you do not want to bother with a server at all (other then serving static files).

AJ Snow17:02:34

yeah a map is what i've been using to play around with resolvers. however when we build for production my understanding is the jar expects to run on a server set up in postgres. so the problem I'm trying to understand is how to appropriately replace postgres in that context, I think. that's why I asked about http kit. it's simple enough in dev, since you just spin up the shadow-cljs server. translating that into production has not been quite so easy for me.

tony.kay17:02:46

PostgreSQL is a server process. That has nothing at all to do with Fulcro in front or back end (in terms of infra)

tony.kay17:02:17

PSQL can run one same machine in small infra, or in a dedicated cluster on larger infra

tony.kay17:02:38

it’s just a network connection via JVM JDBC…again, nothing at all to do with Fulcro

tony.kay17:02:41

it’s just a database

tony.kay17:02:41

JAR is a zip file containing code. Jar runs in JVM. That JVM could be running on a dedicated machine, a Docker container, Datomic Ions on an EC2….whatever. It’s a “machine”. Database is another box in the infra diagram.

tony.kay17:02:54

could be same same “box” could be different “box”.

tony.kay17:02:33

Resolvers are units of construction for the Pathom library. Each unit of code describes how to “resolve” an edge of your data graph, and you write the body. The body has to query whatever database you use (in this case PSQL over a network connection, possibly localhost loopback) to fulfill that requirement.

AJ Snow06:02:37

right I understand psql is its own thing that has a db and server component. but to what extent is fulcro stand-alone? you've got the front end which compiles to js, and then the backend compiles to a jar. but you still need an http server to communicate requests right? i'd need to spin up a process to listen for requests.

jmayaalv07:02:31

But the backend is not required. You can have all the pathom resolvers (the backend) running on js.

jmayaalv07:02:57

If you don't have backend then you don't need http communication

Jakub Holý (HolyJak)07:02:41

> psql is its own thing that has a db and server component no, Postgres does not have a DB and server component, Postgres is a DB, that works in client-server mode. Or did you mean something else? > the backend compiles to a jar. > but you still need an http server to communicate requests right? the jar is executable and spins up its own HTTP server, see https://github.com/fulcrologic/fulcro-template/blob/master/src/main/app/server_components/http_server.clj#L14 And as @U0J6U23FW writes, you can run Fulcro fully in the browser, Pathom included.

tony.kay02:02:22

The JAR contains an embedded HTTP server (http-kit I think is the one I use in the template). Normally you will run that in a docker container or cloud instance of some kind, and put a load balancer in front of it (which will also supply SSL support) and proxy requests to this back-end http server. But, if you were to run the JAR on your own instance and have it use port 80 it would not need any other http server. The need for an additional http server has more to do with infra convenience (SSL cert support, load balancing, etc.).

AJ Snow05:02:49

ah! so I was on the right track then. I was confused as to if http-kit would be enough, but my understanding now from what you all are saying is that it is; assuming I'm not adding any other extra, external stuff in. I will look into this and http kit further and try to get this working. Thank you all for your patience with me!

3
yubrshen01:02:07

Very likely if you want to run a web server (http/run-server) for your server side. Here is the sample code from Tony's Fulcro-3 tutorial:

(ns user
  (:require [org.httpkit.server :as http]
            [app.server :refer [middleware]]
            [clojure.tools.namespace.repl :as tools-ns]
            [taoensso.timbre :as log]))

;; make sure not to find things in place like resources
(tools-ns/set-refresh-dirs "src" "dev")

(defonce server (atom nil))

(defn start []
  (let [result (http/run-server middleware {:port 3000})]
    (log/info "Started web server on port 3000")
    (reset! server result)
    :ok))

(defn stop []
  (when @server
    (log/info "Stopped web server")
    (@server)))

(defn restart []
  (stop)
  (log/info "Reloading code")
  (tools-ns/refresh :after 'user/start))

AJ Snow04:02:00

thank you!

Carlo18:02:24

What should I modify to use guardrails in a shadow-cljs project? In the readme there's a:

When you run a REPL or CLJS compiler, include the JVM option -Dguardrails.enabled.
but I invoke my repl from CIDER, and I'm not sure what I should change

Carlo19:02:46

can I enable it in some configuration file?

yubrshen19:02:08

Check out this https://github.com/clojure-emacs/cider/issues/2396 I was able to add -A:dev option for Clojure REPL with

(setq cider-clojure-cli-global-options "A:cljs")

Carlo20:02:25

thanks @U2QGRCMSM! I tried doing:

(setq cider-clojure-cli-global-options "Dguardrails.enabled")
and also tried adding -Dguardrails.enabled to the prompt with which I launch the repl:
[nREPL] Starting server via /run/current-system/sw/bin/npx shadow-cljs -Dguardrails.enabled -d nrepl/nrepl:0.8.3 -d cider/piggieback:0.5.2 -d refactor-nrepl:2.5.0 -d cider/cider-nrepl:0.25.5 server
None of these approaches worked for me. I also took a look at https://github.com/gothinkster/clojurescript-keechma-realworld-example-app/blob/master/guardrails.edn but I can find the mention of guardrails only in the guardrails.edn file, I can't find how it's actually invoked

Carlo20:02:17

keep in mind that, if it's not throwing, the error will be just a warning in the browser's console

yubrshen04:02:08

Sorry to have misled you. I assumed that you had correct configuration, but need it work with emacs/Cider. Thanks for sharing the working configuration.

Carlo17:02:02

not at all @U2QGRCMSM, thanks for the help!

Jakub Holý (HolyJak)21:02:33

@tony.kay would you accept PR to add :com.fulcrologic.rad.report/column-class to report-options or do you still want to wait with it a while?

tony.kay22:02:00

@holyjak I’d prefer not to add it there. These should really be part of the rendering plugin’s options, since that renderer might support rendering the thing in any manner of ways (not just table). I realize “report” is table-centric in RAD “by default”, but I want to leave as much of the “chrome config” to the UI plugins…so I’d take a PR against rad SUI plugin 😄

👍 3
Jakub Holý (HolyJak)07:02:22

That makes sense. Though, on the other hand, "column" is a generic enough column and since we can be 99% sure it will be represented by a HTML element (or a stylable native element), it perhaps makes sense to have column-class where it is now, in c.f.rad.report? I wouldn't know how to go about the SUI PR because the code is an interesting mixture where the column-classes getter is in c.f.rad.report and so are the keys ::report/column-class and ::report/column-classes . So it would feel strange to add com.fulcrologic.rad.rendering.semantic-ui.report-options/column-class[es] for them... What do you think/suggest?

tony.kay02:02:57

Yeah, this is why I just haven’t acted. I have the same concern. Technically, though, RAD supports Native so a “class” really is a rendering artifact of HTML that isn’t tied to RAD core….but this is such a common case that it may really just deserve a core option.

👍 3
tony.kay02:02:39

Sure, go ahead and send a PR for the option with a docstring, just note that it is a HINT to a HTML render plugin.

AJ Snow06:02:37

right I understand psql is its own thing that has a db and server component. but to what extent is fulcro stand-alone? you've got the front end which compiles to js, and then the backend compiles to a jar. but you still need an http server to communicate requests right? i'd need to spin up a process to listen for requests.