Fork me on GitHub
#biff
<
2022-12-15
>
Lyn Headley02:12:03

Is there a recommended way of creating and destroying short-lived databases used for holding test fixtures?

Lyn Headley02:12:24

Maybe (xt/start-node {}) is all I need

☝️ 1
macrobartfast03:12:36

I am playing around with hitting endpoints on the server… essentially creating an API that doesn’t use credentials for now. The app is on DO at the moment. A GET worked great (which calls a function that does something arbitrary on the server). However, a POST call returns a 403/<h1>Invalid anti-forgery token</h1>. Probably the right question is: how would I create an API for a Biff app so that other things can trigger events on the server (hardware buttons on Arduinos or the like/scripts on devices/etc). Can I issue credentials to users to make calls? In the case of, say, an Arduino I could bake the credential into the calls the device makes. Presumably a user would have an account on a Biff app first, then one would issue a credential that is tied to them. Just brainstorming here. I’m a fan of Swagger UI docs, btw… but that is outside the scope of this question but mentioning it since, down the road, it would be sweet to have automatic interactive documentation for the endpoints. I realize credentials and the anti forgery issue are probably separate ones. My immediate quick and dirty need is to be able to POST form data to a Biff app on DO but not from the context of a logged in user on a web page.

Jacob O'Bryant03:12:44

Put the routes under an :api-routes key in your features map instead of the :routes key. That'll disable the csrf token check.

macrobartfast03:12:11

haha… 2000 word question, one line solution.

🙂 1
Jacob O'Bryant03:12:26

You could add a :user/access-token attribute and store the random token there when the user clicks "generate token" or whatever. Then make some wrap-api-token middleware that checks the Authorization header for the existence of the token, and use it to wrap all the :api-routes routes.

Jacob O'Bryant03:12:04

I think reitit might have stuff for generating swagger docs?

macrobartfast03:12:50

It does I’m pretty sure, and Biff uses reitit. It’s all wonderfully possible!

pavlosmelissinos22:12:57

FYI, https://github.com/jacobobryant/biff/blob/9c11643516e8526a75c761f77139014241d5f114/new-project.clj#L13 if you are unfortunate enough to have a custom _JAVA_OPTIONS env variable (I've set it to force java into using ~/.config/java instead of ~/.java). Repro and suggested solution in:thread:

pavlosmelissinos22:12:18

A warning appears at the beginning of the output of java -version, which trips up the indexes 😞 For example:

Picked up _JAVA_OPTIONS: -Djava.util.prefs.userRoot=/home/pavlos/.config/java
openjdk version "19.0.1" 2022-10-18
Replacing (nth 2) with
(as-> $ (drop-while #(not= % "version") $))
(nth 1)
seems to be working for me and depending on the version number being right after "version" seems ok to me (still kinda flaky but probably less likely to break) Would you be interested in a PR?

Jacob O'Bryant22:12:55

A PR would be great--sorry about that!

pavlosmelissinos22:12:48

Nah, installation was too easy before anyway 😉 (PR on the way)

🙂 1
pavlosmelissinos22:12:07

Wow, I was about to give you a proper repro case in case you wanted to test it on another machine but thanks for merging so quickly :the_horns:

Jacob O'Bryant22:12:20

haha no worries, already tested on my machine

pavlosmelissinos22:12:37

cool, thanks 🙂

Jacob O'Bryant22:12:40

the new script is on http://biffweb.com now, so the regular new project command should work

😎 1