biff 2024-08-03

Came across this old post mentioning a possible example of using Stripe with Biff: https://clojurians.slack.com/archives/C013Y4VG20J/p1695740476351439?thread_ts=1695735519.776049&cid=C013Y4VG20J Does anyone have an example? (Sorry I'm sure this isn't even really biff specific as it would just be talking to an API).

I'm not aware of any published examples, but I've found it's been pretty straightforward to follow the stripe docs using their curl examples. I would recommend using the REST API directly rather than going through the java sdk. I'll take a few snippets from one of my apps and paste it in a gist--won't be super polished, or generalized, but should still have some helpful bits.

Here are some examples: https://gist.github.com/jacobobryant/c133a95efb6304b9e32610869acb4116. I'll add a link to that in the content library.

I've worked with stripe and biff as well, there's nothing particularly special about the interaction, it's more about how you structure your app.

Awesome thanks!

When using the deployment script, can you have multiple apps and xtdb instances deployed to the same droplet? Or do you need a separate droplet for each?

It won't work with the default server-setup.sh script out of the box, but it could be done with some effort. You could either put each app in a subdirectory of the app user's home folder, like /home/app/app1, /home/app/app2 etc; or you could make a different user for each app, like /home/app1, /home/app2 etc. I'd probably just go the subdirectory route. So in that script, you'd need to: • create a separate systemd service for each app, with different WorkingDirectory values • modify the nginx config so it sends requests to different ports based on the domain • (optional) change the set_up_app bit so it creates a separate git repo for each app. This is only necessary if you're deploying from windows; otherwise clj -M:dev deploy and clj -M:dev soft-deploy will just use rsync to upload your files. And some other stuff: • When you run that script and it executes the certbot --nginx command, you'd also need to enter in multiple domains/subdomains, one for each app. • You'd need to update the :biff/port setting in resources/config.edn in each app so they're not all trying to listen on the same port. • You'll also need to update the clj -M:dev deploy / clj -M:dev soft-deploy tasks so they upload your local files to e.g. /home/app/app1 instead of /home/app. See https://github.com/jacobobryant/biff/blob/502a4f5414a82ab96c7fd6809aef142bf807c0e7/libs/tasks/src/com/biffweb/tasks.clj#L139: you'd need that to be something like [(str "app@" server ":" app-dir "/")], where app-dir is a value like "app1", taken from the app's config. The https://biffweb.com/p/how-to-use-postgres-with-biff/ and https://biffweb.com/p/how-to-use-re-frame-with-biff/ both have examples of overriding the default tasks. All that being said: if you're deploying to a cloud VPS like digitalocean, I would just use a separate droplet/vps for each app. In my testing, you have to have 1gb of ram just to run the starter project, otherwise it crashes on startup. So if you're running multiple JVMs you'll most likely have to scale up the droplet, and a 2gb droplet isn't any cheaper than just getting two 1gb droplets. It might make sense if you're deploying them to a home server/bare metal server though.

Very helpful, thanks!