5.4 KiB
Climbing Tracker
A climbing tracker for Alysia and her friends: log climbs (with photos), see progress, set goals, schedule group sessions. Alysia directs the work and has no coding experience, so explain things in plain language and choose sensible technical defaults rather than asking her technical questions.
The app is live at https://n0m.org/act/ and real people's data is stored there. n0m.org is Ben's personal server and also hosts other things, so treat it gently (see "Things that can hurt n0m").
Layout
src/— the React app (one page, built with Vite). All data handling goes throughapi.shrelative to the page.cgi/api.sh— the server-side data API, a bash CGI script built oncgi/exprash.sh(Ben's Express-like router for bash; treat it as a vendored library).vite.config.js— also contains a dev-server stand-in forapi.shthat answers at the same addresses and stores data indata/locally. Any change tocgi/api.shneeds the matching change here, and vice versa.scripts/deploy.mjs— uploadsdist/to n0m over SFTP.data/— local dev data only (gitignored). The real data is on the server.
Running and deploying
npm run dev— local version at http://localhost:5173 with its own separate test data.npm run upload— builds, uploads to theactcontainer, then checks the live site serves the new page and that saved data still loads.
Alysia has asked for changes to go online as soon as they are tested: test locally first, deploy, then tell her plainly that it is online (or that it failed).
The deploy needs a .env file containing N0M_MODIFY_PASSWORD (see .env.example). It is the container's "Modify Password" and gives full read/write/delete access to everything in the container, including everyone's data. Never commit it, print it, or put it anywhere but .env.
What lives on the server
Inside the act container, next to the uploaded app files:
data/users/<id>.json one file per profile (climbs, goals, sessions, RSVPs…)
data/photos/<id>-<photo id>.jpg
data/backups/ one copy per profile per day, taken before that day's first save
data/.auth/<id> password hash for a profile
data/.auth/_pepper random secret mixed into the password hashes
Never upload to, overwrite or delete anything under data/. deploy.mjs refuses to run if dist/ contains a data/ folder; keep that check.
A forgotten profile password is reset by deleting data/.auth/<id> (over SFTP with the modify password, or Ben can do it). The next sign-in then asks for a new password. Deleting _pepper would invalidate every password.
How n0m serves a files container
These quirks shaped the design. Check them before changing how the app talks to the server.
- Any non-executable file is downloadable by URL, including files in dot folders, and folders are listable. Nothing in the container is private unless it is executable.
- Executable files are run as CGI scripts instead of being sent. That is why
api.shmust keep its execute bit, and why the secret files indata/.auth/start with#!/bin/trueand are mode 700: requesting them runstrueand returns nothing. - Scripts run in a sandbox (bubblewrap) with the container mounted read-write and no network access. So the server cannot send push notifications, emails or call other services. Standard tools from
/usr/binare available; do not assumejq. - Request bodies reach a script only if they are JSON or URL-encoded, and at most 100 KB. Anything else arrives empty. This is why each profile is saved as one JSON document (it must stay under 100 KB), and why photos are compressed in the browser to 64 KB and sent as base64 inside JSON.
- A URL that continues past a script's file name hangs forever (e.g.
api.sh/users/x). Use query strings (api.sh?user=x). - File types are guessed from content, not extension, except
.js, and.css/.htmlwhen the guess is plain text. The app's CSS is therefore inlined into the JS bundle rather than served as a stylesheet. - The first file whose name starts with
indexis served as the folder's page. Do not put otherindex*files in the container root.deploy.mjsnames its temporary filesdeploy-tmp-…for this reason. - A script's response must start with a
Content-Typeheader line (Exprash'ssenddoes this).
n0m's SFTP server
sftp://n0m.org:2222, username = container keyword (act), password = the modify password. It is a small custom server, not OpenSSH:
- SFTP only: no shell, no exec, so no rsync or scp. Password login only.
- Implemented: STAT, OPEN, READ, WRITE, CLOSE, OPENDIR/READDIR, MKDIR, RMDIR, REMOVE, RENAME, SETSTAT.
- Not implemented: LSTAT, FSETSTAT, symlinks.
- MKDIR fails if the folder exists. SETSTAT can only change the owner's execute bit.
- The host key fingerprint is pinned in
scripts/deploy.mjs.
Things that can hurt n0m
Ben knows the n0m code has rough edges and has asked that we avoid tripping them:
- Never chmod (SETSTAT) a path that does not exist on the SFTP server. It has no error handling there and may take the whole n0m process down.
deploy.mjsonly chmods a file it has just uploaded. - Prefer the operations
deploy.mjsalready uses over general-purpose SFTP clients, which lean on the unimplemented ones. - If n0m itself misbehaves (every script on the site failing, uploads refused), that is Ben's to fix on the server. Tell Alysia to ask him rather than working around it.