chore: Add deploy plumbing for the share service

Add a hardened systemd unit, a Caddy reverse-proxy snippet that maps
/fabula/api/* to the loopback service, and Justfile build-server/
deploy-server recipes that build a static binary and ship + restart it.
Includes server/README documenting the API, config, and deploy steps.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-17 02:01:37 +00:00
parent 6609956711
commit 410eb3a5a8
4 changed files with 121 additions and 0 deletions

51
server/README.md Normal file
View File

@@ -0,0 +1,51 @@
# share-svc
Tiny Go + SQLite service that stores character-sheet JSON blobs and returns
short, content-addressed IDs, so sheets share as `...?s=<id>` instead of a giant
inline `?c=` payload.
## API
| Method | Path | Body | Response |
| ------ | ------------ | ----------- | ------------------- |
| POST | `/api/s` | sheet JSON | `{"id":"<id>"}` |
| GET | `/api/s/{id}`| | sheet JSON |
IDs are `base64url(sha256(json))[:12]`, so identical sheets dedupe and re-sharing
is idempotent. Payloads are stored deflated in a single SQLite file.
### Config (env)
| Var | Default | Notes |
| ------------- | ------------- | ------------------------------------------------ |
| `ADDR` | `:8090` | Listen address. The unit binds `127.0.0.1:8090`. |
| `DB_PATH` | `shares.db` | SQLite file path. |
| `CORS_ORIGIN` | _(unset)_ | Set to allow a cross-origin dev frontend. |
## Deploy
From the repo root:
```sh
just deploy-server # build (linux/amd64) + ship + restart
just go-arch=arm64 deploy-server # if the host is arm64
```
That installs `/usr/local/bin/share-svc` and `share-svc.service`, then
`daemon-reload` + `enable --now` + `restart`. The SQLite DB lives in
`/var/lib/share-svc/` (created by the unit's `StateDirectory`).
### One-time Caddy setup
Add the `/fabula/api/*` reverse-proxy block from `Caddyfile.snippet` to your site
block (before the static `/fabula/*` handler) and reload Caddy.
## Local dev
`webpack serve` (port 8080) does not serve `/api/*`, so `?s=` sharing falls back
to inline `?c=` links. To exercise short links locally, run the service and point
the frontend at it:
```sh
CORS_ORIGIN=http://localhost:8080 go run ./server
```