Fork me on GitHub
#biff
<
2023-09-19
>
Chip13:09:45

I have started from scratch. Yesterday, I deployed before making any changes (Postmark, reCaptcha). Shall I do that again or make sure Postmark and reCaptcha are working in dev before deploying? I will also skip the PostgreSQL backend in production when I create the droplet.

Martynas Maciulevičius14:09:25

You can redeploy many times. The only problem is that when you'll deploy without postgres and create a database then you'll have a new database as the old one will remain on the droplet itself but won't be used.

Martynas Maciulevičius14:09:58

You can create postgres in the cloud and then connect from local bb dev too. It will work the same as in production. Then you'll know that it will work the same after deployment.

Jacob O'Bryant14:09:39

definitely make sure it's working in dev before you bother with deploying

gratitude-thank-you 1
Jacob O'Bryant15:09:01

basically just start a new project, make sure it works, then add postmark and recaptcha config to config.edn, then hit ctrl-c on the app and run bb dev again, then see if that works

Chip15:09:14

set POSTMARK_API_KEY only in secrets.env, right? Line https://github.com/jacobobryant/biff/blob/b730c8524fa113832865b6f41312dd87a514465f/example/config.edn.TEMPLATE#L16 doesn’t have the ; Leave this as-is, and update secrets.env comment like line https://github.com/jacobobryant/biff/blob/b730c8524fa113832865b6f41312dd87a514465f/example/config.edn.TEMPLATE#L9C53-L9C95 does. Just checking. That’s how I configured it last time.

Chip15:09:40

Just like yesterday, bb dev works fine out of the box. Again, yesterday I deployed without changing anything.

👍 1
Chip15:09:14

I’m configuring reCaptcha and Postmark now.

👍 1
Chip15:09:46

Ok. With…

secrets.env
   set POSTMARK_API_KEY
   set RECAPTCHA_SECRET_KEY

config.edn
   set :postmark/from (to match Postmark sender signature)
   set :recaptcha/site-key
Seeing the same behavior, sign in and sign up stay on the home page. Nothing in the logs other than the / route for signup and /signin for sign in.
% bb dev                                                       

Rebuilding...

Done in 395ms.
[main] INFO life - starting: com.biffweb$use_config@5de1b3ee
[main] INFO life - starting: com.biffweb$use_secrets@31e6ac68
[main] INFO life - starting: com.biffweb$use_xt@6b8eec09
[main] INFO xtdb.tx - Started tx-ingester
[main] INFO com.biffweb.impl.xtdb - Indexed #:xtdb.api{:tx-time #inst "2023-09-19T14:58:38.444-00:00", :tx-id 7}
[main] INFO life - starting: com.biffweb$use_queues@f24af6f
[main] INFO life - starting: com.biffweb$use_tx_listener@7194cf53
[main] INFO life - starting: com.biffweb$use_jetty@3a4b7322
[main] INFO org.eclipse.jetty.server.Server - jetty-10.0.7; built: 2021-10-06T19:34:02.766Z; git: da8a4553af9dd84080931fa0f8c678cd2d60f3d9; jvm 20.0.2.1+10-FR
[main] INFO org.eclipse.jetty.server.handler.ContextHandler - Started o.e.j.s.ServletContextHandler@4b6bdffe{/,null,AVAILABLE}
[main] INFO org.eclipse.jetty.server.AbstractConnector - Started ServerConnector@466ea2b0{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
[main] INFO org.eclipse.jetty.server.Server - Started Server@2d8554ff{STARTING}[10.0.7,sto=0] @23908ms
[main] INFO com.biffweb.impl.misc - Jetty running on 
[main] INFO life - starting: com.biffweb$use_chime@16c2ec2a
[main] INFO life - starting: com.biffweb$use_beholder@43508da7
[chime-1] INFO life.worker - There are 2 users.
[main] INFO life - System started.
[main] INFO life - Go to 
nREPL server started on port 7888 on host localhost - 
[qtp1285414362-41] INFO com.biffweb.impl.middleware -  34ms 101 get  /app/chat
[qtp1285414362-37] INFO com.biffweb.impl.middleware -  30ms 303 post /auth/signout
[qtp1285414362-39] INFO com.biffweb.impl.middleware -  14ms 200 get  /
[qtp1285414362-35] INFO com.biffweb.impl.middleware -  20ms 200 get  /js/main.js?t=1695129134913
[qtp1285414362-42] INFO com.biffweb.impl.middleware -  24ms 200 get  /css/main.css?t=1695129186719
[qtp1285414362-37] INFO com.biffweb.impl.middleware -   4ms 200 get  /signin
[qtp1285414362-39] INFO com.biffweb.impl.middleware -   6ms 200 get  /signin
[qtp1285414362-36] INFO com.biffweb.impl.middleware -   0ms 200 get  /img/glider.png
[qtp1285414362-40] INFO com.biffweb.impl.middleware -   3ms 200 get  /
[qtp1285414362-36] INFO com.biffweb.impl.middleware -   3ms 200 get  /signin
[qtp1285414362-40] INFO com.biffweb.impl.middleware -   2ms 200 get  /
[qtp1285414362-36] INFO com.biffweb.impl.middleware -   1ms 200 get  /img/glider.png
[qtp1285414362-35] INFO com.biffweb.impl.middleware -   5ms 200 get  /signin
[qtp1285414362-40] INFO com.biffweb.impl.middleware -   5ms 200 get  /
[chime-1] INFO life.worker - There are 2 users.
[qtp1285414362-37] INFO com.biffweb.impl.middleware -   3ms 200 get  /signin
[qtp1285414362-40] INFO com.biffweb.impl.middleware -   3ms 200 get  /
What info would be useful? Where do I check next?

Jacob O'Bryant16:09:55

try opening the developer console -> network tab, then click the sign up button. does it show that a request is being triggered? if so, what are the parameters in the request?

Chip16:09:16

The request isn’t triggered. I can send you the call history for each route if you’d like.

Jacob O'Bryant16:09:03

I'm guessing it's a recaptcha misconfiguration

Jacob O'Bryant16:09:19

since when recaptcha is enabled, it's in charge of triggering the request

Chip16:09:13

Makes sense. I do have to register the URL. Maybe that’s it?

Jacob O'Bryant16:09:31

For dev, you just need to make sure you have localhost in your list of allowed domains

Jacob O'Bryant16:09:01

if you've done that and it's still not working, I would put some prints in this function: https://github.com/jacobobryant/biff/blob/master/example/src/com/example/home.clj#L15 e.g. (prn site-key) and also (prn ((:biff/secret ctx) :recaptcha/secret-key)) <- don't paste the result of that here since it's a secret just make sure those printed values look correct

Chip16:09:40

That was it. reCaptcha needed the localhost entry. Another rookie mistake. 1000 pardons. Thank you. Deploy (without the database)?

Jacob O'Bryant16:09:35

Excellent, glad to hear it's working 🙂 . Sure, if it's working locally now, go ahead and deploy. with or without postgres is fine, up to you.

Chip16:09:03

thanks again

👍 1
chromalchemy14:09:08

I am working through tutorial and have a basic site going with routing working to load pages. No errors in bb-dev output 😅 What is the current best practice to auto-refresh the browser on code changes (especially crucial for iterative CSS changes) Currently I must manually refresh browser. I do see the on-save fn. But it looks like it does not refresh browser by default? Is this current thinking? https://github.com/jacobobryant/biff/issues/117 I would prefer a non-live.js solution, as I have experienced that to be flakey in the past, even with a plain SSG build (it would reload html, but not css, until you focused the browser window). Would be nice to have it all in clj to reason about (Have watcher and server alread…) I’m thinking solution probably should use a websocket or ring somehow, like… https://github.com/AdamFrey/clojure-html-server-live-reload-template https://github.com/weavejester/ring-refresh https://github.com/keychera/panas.reload Any examples out there?

Jacob O'Bryant15:09:42

agreed using a websocket instead of live-reload.js (I.e. polling) would be better. the approach described in the first post of that biff github issue is still how I'd do it. in fact one of the changes I recently made in v0.7.11 was to update biff/eval-files! so it returns the code refresh result instead of nil. so you can modify on-save to look at that return value. then you just need to take that data and use it to send a websocket message to the front end

Jacob O'Bryant15:09:12

I think htmx will make that fairly straightforward actually

Jacob O'Bryant15:09:46

also probably want to have some kind of config option so it only happens in local dev

Jacob O'Bryant15:09:38

if the refresh is successful, you can send a message like [:div {:_ "init call window.location.reload()"}] and if it's unsuccessful then show a heads up display with the stack trace or something

chromalchemy15:09:38

Ok thanks for pointers. I don’t yet have much experience with htmx or websockets yet, but will try.

👌 1
Jacob O'Bryant15:09:13

see app.clj in the starter app for an example of using websockets with htmx, you should be able to just copy that for the most part

chromalchemy15:09:32

I dont see app.clj in biff example. https://github.com/jacobobryant/biff/tree/36cfe9b291185c9300239770059fd0e72a2bea05/example/src/com/example Where is that reference? I have one in the eelchat tutorial codeboase, but I’m not seeing the pattern there…?

chromalchemy16:09:26

Is this it? https://github.com/jacobobryant/eelchat/blob/master/src/com/eelchat/app.clj I guess that’s the codebase I am working off, but the tutorial had me already delete a lot of that stuff.. Will re-introduce.

Chip16:09:19

Did you successfully configure Postmark and reCaptcha?

chromalchemy16:09:17

Haven’t got that far yet. I did a dry run hello world 4mo ago and believe I got recaptcha working then…

gratitude-thank-you 1
Jacob O'Bryant16:09:33

this is the file I was referring to: https://github.com/jacobobryant/biff/blob/master/example/src/com/example/app.clj (has basically the same websocket bits in it as eelchat; either works as an example)

chromalchemy16:09:01

Ok, thank you for the pointers. I was able to get live.js working based off your commit above!! 🙌 (a bit painful, but good practice I guess to get a feel more modifying the codebase) It’s a bit slow, still feels flakey. Html updates take 1s, css updates 4s. (Will have to time my css build fn, maybe thats the culprit…). But at least they are reloading automatically.. I will try the htmx websocket implementation when I have more time to grok the parts.

Jacob O'Bryant16:09:07

great 🙂 one caveat that just occurred to me: the on-save function by default won't run when your css file is updated. I think it'll work if you put this in config.edn:

:biff.beholder/paths ["src" "resources" "target"]
:biff.beholder/exts [".clj" ".css"]
(see use-beholder: https://github.com/jacobobryant/biff/blob/master/src/com/biffweb/impl/misc.clj#L16)

👀 1
Jacob O'Bryant16:09:33

looking sweet 🙂 love the design also

ianjones16:09:51

trying out neo-brutalism

ianjones16:09:32

this has been used as a reference https://gumroad.com/

Chip20:09:41

Beginner question: why have a separate secrets.env file when config.edn isn’t under source control either? Just wondering.

Jacob O'Bryant20:09:46

I will probably add config.edn to source control by default actually. Originally secrets were stored verbatim in config.edn, but I moved them out because it's common for various deployment environments to let you store secrets in env vars and I wanted to make it easy to see how to make that work with biff. (whereas for regular config I'm OK with being more rigid and saying "just put it in this edn file.") Also I wanted to make it a little harder for people to accidentally expose their secrets, e.g. by pasting the contents of their config.edn when asking for help, or by logging the system map to the console and having that get stored in a logging service

Chip21:09:21

Ahhh. Thank you. Thoughtful on several levels.

Martynas Maciulevičius21:09:25

I proposed to move almost all of those out of secrets.edn file so that it would be consistent because some of them are loaded from env vars but others are loaded directly from secrets.edn.