Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cbaac91138 | |||
| 1eb69e0317 | |||
| a883a60a83 | |||
| 67ad9701c1 |
@@ -0,0 +1,7 @@
|
|||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
data
|
||||||
|
.env
|
||||||
|
.git
|
||||||
|
tests
|
||||||
|
*.md
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# Stage 1: build
|
||||||
|
FROM node:22-slim AS build
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
RUN npm ci
|
||||||
|
COPY . .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Stage 2: runtime
|
||||||
|
FROM node:22-slim AS runtime
|
||||||
|
WORKDIR /app
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
RUN npm ci --omit=dev && npm cache clean --force
|
||||||
|
COPY --from=build /app/dist ./dist
|
||||||
|
COPY scripts ./scripts
|
||||||
|
# Contenuti del Biohacking Campus (generati con sync-campus e committati nel repo)
|
||||||
|
COPY campus-content ./campus-content
|
||||||
|
|
||||||
|
# Tre database distinti, tutti nello stesso volume:
|
||||||
|
# - piattaforme.db utenti e sessioni di quest'app (NON quelli del sito)
|
||||||
|
# - longevity.db misure e punteggi, senza nomi
|
||||||
|
# - identity.db la mappatura codice ↔ persona, l'unico file con dei nomi dentro
|
||||||
|
ENV HOST=0.0.0.0 \
|
||||||
|
PORT=4321 \
|
||||||
|
DB_PATH=/app/data/piattaforme.db \
|
||||||
|
LONGEVITY_DB_PATH=/app/data/longevity.db \
|
||||||
|
IDENTITY_DB_PATH=/app/data/identity.db
|
||||||
|
EXPOSE 4321
|
||||||
|
CMD ["node", "./dist/server/entry.mjs"]
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
# InsanityLab — aree riservate (`piattaforme.tielogic.xyz`)
|
||||||
|
|
||||||
|
Applicazione Astro autosufficiente con le tre aree riservate: **Biohacking Campus**,
|
||||||
|
**Stress Index** e **Longevity**. Nasce il 03/09/2026 separando dal sito
|
||||||
|
(`apps/sito`, `insanitylab.it`) tutto ciò che sta dietro un login.
|
||||||
|
|
||||||
|
## Cosa la rende separata
|
||||||
|
|
||||||
|
| | Sito | Quest'app |
|
||||||
|
|---|---|---|
|
||||||
|
| Host | `insanitylab.it` | `piattaforme.tielogic.xyz` (in futuro anche `apps.insanitylab.it`) |
|
||||||
|
| Utenti | 3 redazionali (`admin`, `superuser`, `user`) | uno per ogni cliente del centro (`piattaforme`, `cliente`, `trainer`, `admin`) |
|
||||||
|
| Database | `insanitylab.db` (contenuti, articoli, utenti del sito) | `piattaforme.db` + `longevity.db` + `identity.db` |
|
||||||
|
| Login | `/admin/login`, solo redazione | `/login`, ed è l'unica porta |
|
||||||
|
|
||||||
|
Non c'è SSO e non c'è cookie condiviso: **una sessione del sito qui non vale**, ed è la
|
||||||
|
separazione, non un difetto. Le due `lib/auth.ts` sono parenti ma non sono la stessa cosa —
|
||||||
|
~170 righe duplicate una volta sola, libere di divergere come già divergono i ruoli.
|
||||||
|
|
||||||
|
## Sviluppo
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm ci
|
||||||
|
npm run dev # http://localhost:4321
|
||||||
|
npm test # 32 file, 261 test (26/09/2026)
|
||||||
|
npm run create-user -- <nome> <password> <ruolo> # ruoli: piattaforme, cliente, trainer, admin
|
||||||
|
```
|
||||||
|
|
||||||
|
I dati stanno in `data/` (gitignorata): `piattaforme.db`, `longevity.db`, `identity.db`.
|
||||||
|
|
||||||
|
## Longevity: cosa c'è
|
||||||
|
|
||||||
|
| Chi | Dove | Cosa fa |
|
||||||
|
|---|---|---|
|
||||||
|
| `trainer`, `admin` | `/longevity/gestionale` | elenco clienti, nuovo cliente (apre il fascicolo su identity e longevity), scheda cliente con referto, sessioni e **misure da verificare** (conferma/scarta), nuovo check-up con i 24 test fisici `f_`, **crea accesso** al referto (password mostrata una volta) |
|
||||||
|
| `cliente` | `/longevity/io`, `/longevity/progressione`, `/longevity/questionario` | il proprio referto (radar, macro-score, Fitness Age), l'andamento nel tempo, il questionario |
|
||||||
|
|
||||||
|
`/longevity` smista: staff al gestionale, cliente al referto. Ogni pagina ha un'uscita:
|
||||||
|
il referto porta «Piattaforme» e, allo staff, «← Gestionale».
|
||||||
|
|
||||||
|
Il calcolo di una sessione usa, per ogni test, **la misura valida più recente del cliente fino
|
||||||
|
alla data della sessione** (`misureValideAlla` in `lib/longevity/motore/index.ts`): check-up e
|
||||||
|
questionario sono sessioni separate e si combinano. Una misura fuori dal range di plausibilità
|
||||||
|
non conta finché il trainer non la conferma; confermarla ricalcola quella sessione e le
|
||||||
|
successive. `FINESTRA_GIORNI = null`: oggi una misura non scade — la durata la decide Nicola.
|
||||||
|
|
||||||
|
Fuori per ora: import Wellness Tower e dinamometro (#3), percentili interni (#4). Il consenso ai
|
||||||
|
dati sanitari è firmato su carta prima dell'accesso (decisione di Adriano, 26/09, #6).
|
||||||
|
|
||||||
|
## Rilascio
|
||||||
|
|
||||||
|
⚠️⚠️ **Il DNS viene prima del container.** `apps.insanitylab.it` deve già risolvere verso
|
||||||
|
l'IP della VPS quando si alza lo stack: avviarlo prima significa una catena di sfide TLS
|
||||||
|
fallite, e Let's Encrypt limita proprio quelle. La zona è su **Aruba**, serve un record
|
||||||
|
**A** `apps` → l'IP della macchina.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir -p /opt/docker/insanitylab-platforms/data # i dati stanno FUORI dal clone git
|
||||||
|
docker compose up -d --build
|
||||||
|
node scripts/migra-utenti.mjs # prova a vuoto
|
||||||
|
node scripts/migra-utenti.mjs --applica # porta gli utenti dal DB del sito
|
||||||
|
```
|
||||||
|
|
||||||
|
**Aggiornare una versione già in linea** (checkout `/opt/docker/insanitylab-apps`, su `main`):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
D=/opt/docker/insanitylab-platforms/data; B=/opt/docker/insanitylab-platforms/backup/$(date -u +%Y%m%dT%H%M%SZ)
|
||||||
|
mkdir -p $B && for f in longevity identity piattaforme; do sqlite3 $D/$f.db ".backup '$B/$f.db'"; done
|
||||||
|
git pull --ff-only origin main
|
||||||
|
cd apps/platforms && docker compose up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
⚠️ **I dati veri sono in `/opt/docker/insanitylab-platforms/data`** (il volume del compose), non
|
||||||
|
in `apps/platforms/data` del checkout: quella è una copia vecchia che il container non legge.
|
||||||
|
|
||||||
|
⚠️ **Il database di Longevity si apre alla prima richiesta autenticata**, non all'avvio: le
|
||||||
|
migrazioni (`migra()` in `lib/longevity/db.ts`, colonne aggiunte con `ALTER TABLE`) e il seed del
|
||||||
|
registro partono solo allora. Per farle subito, dopo il deploy:
|
||||||
|
`docker exec -w /app insanitylab-platforms node --input-type=module -e 'const m = await import("/app/dist/server/chunks/<chunk db>.mjs"); m.<getLongevityDb>()'`
|
||||||
|
(nome del chunk e dell'export con `grep -l registro_test -r dist/server/chunks`).
|
||||||
|
|
||||||
|
## Trappole già pagate
|
||||||
|
|
||||||
|
⚠️ **Le versioni si fissano esatte.** `^7.0.5` sulla nuova app aveva risolto ad **astro
|
||||||
|
7.3.0**, che con `@astrojs/node 11.1.5` non si parla (`"./_internal/logger" is not
|
||||||
|
exported`) e il build muore. Astro, l'adapter node e l'integrazione react sono pinnati
|
||||||
|
alle stesse versioni che girano in produzione sul sito.
|
||||||
|
|
||||||
|
⚠️ **`security.allowedDomains` in `astro.config.mjs` non è decorativo.** Dietro Traefik il
|
||||||
|
TLS termina al proxy: senza quell'elenco Astro ignora `X-Forwarded-Proto`/`Host` e il
|
||||||
|
controllo CSRF respinge **ogni** POST con 403 — cioè il login smette di funzionare e
|
||||||
|
l'errore sembra «credenziali sbagliate».
|
||||||
|
|
||||||
|
⚠️ **`name: insanitylab-platforms` nel compose.** Senza, il progetto si chiamerebbe
|
||||||
|
`platforms` (dal nome della cartella) e un `down --remove-orphans` dato altrove potrebbe
|
||||||
|
toccare container che non sono suoi.
|
||||||
|
|
||||||
|
⚠️ **Il default di `canAccessPath` è chiuso**, al contrario del sito da cui viene: là le
|
||||||
|
rotte non elencate (blog, upload) erano di chiunque fosse loggato, qui ogni sezione è di
|
||||||
|
qualcuno. Una rotta nuova senza regola risulta **vietata**, e lo si scopre provandola.
|
||||||
|
|
||||||
|
⚠️ **Le API rispondono con uno stato, non con un redirect** (401/403 su `/api/*`): mandare
|
||||||
|
un 302 verso il login a chi ha chiesto del JSON produce un 200 con dentro dell'HTML.
|
||||||
|
|
||||||
|
⚠️ **Due test vietano parole, non codice.** `tests/longevity/anagrafica.test.ts` fallisce se un
|
||||||
|
file `.ts`/`.astro` contiene insieme «Identity» e «Longevity» (anche in un commento): solo
|
||||||
|
`lib/longevity/anagrafica.ts` e `db.ts` possono aprire i due database insieme.
|
||||||
|
`tests/longevity/referto.test.ts` intercetta «select» come SQL, anche l'HTML `<select>`: nei
|
||||||
|
form si usano i radio.
|
||||||
|
|
||||||
|
⚠️ **`node_modules` non si traccia.** Il pattern era `node_modules/`, che ignora le cartelle ma
|
||||||
|
non i symlink: un symlink verso il checkout di produzione era finito in git e un `npm ci` in un
|
||||||
|
clone svuotava la cartella di produzione (#9). Ora il pattern è `node_modules`.
|
||||||
|
|
||||||
|
⚠️ **Stress Index non ha un backend**: `src/lib/stress-index/data.ts` sono dieci clienti
|
||||||
|
inventati scritti a mano. In linea c'è la sua interfaccia, non i suoi dati.
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import { defineConfig } from 'astro/config';
|
||||||
|
import node from '@astrojs/node';
|
||||||
|
import react from '@astrojs/react';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
site: 'https://apps.insanitylab.it',
|
||||||
|
output: 'server',
|
||||||
|
|
||||||
|
// ⚠️ Dietro Traefik il TLS termina al proxy: senza allowedDomains Astro ignora
|
||||||
|
// X-Forwarded-Proto/Host e il checkOrigin CSRF respinge OGNI POST con 403 — cioè
|
||||||
|
// il login smette di funzionare, e l'errore sembra "credenziali sbagliate".
|
||||||
|
// Stessa configurazione del sito, con l'host di quest'app.
|
||||||
|
security: {
|
||||||
|
allowedDomains: [
|
||||||
|
// L'host definitivo, quando il record A su Aruba ci sara'.
|
||||||
|
{ hostname: 'apps.insanitylab.it', protocol: 'https' },
|
||||||
|
// ⚠️ L'host in uso oggi (03/09/2026): il dominio del cliente resta su Aruba e le aree
|
||||||
|
// riservate stanno su un sottodominio nostro. Finche' e' in uso deve stare qui:
|
||||||
|
// senza, dietro Traefik il controllo CSRF di Astro respinge ogni POST con 403 e il
|
||||||
|
// login sembra rifiutare le credenziali.
|
||||||
|
{ hostname: 'piattaforme.tielogic.xyz', protocol: 'https' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
adapter: node({ mode: 'standalone' }),
|
||||||
|
integrations: [react()],
|
||||||
|
});
|
||||||
|
After Width: | Height: | Size: 370 KiB |
|
After Width: | Height: | Size: 230 KiB |
|
After Width: | Height: | Size: 165 KiB |
|
After Width: | Height: | Size: 229 KiB |
|
After Width: | Height: | Size: 255 KiB |
|
After Width: | Height: | Size: 276 KiB |
|
After Width: | Height: | Size: 255 KiB |
|
After Width: | Height: | Size: 222 KiB |
|
After Width: | Height: | Size: 390 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 581 KiB |
|
After Width: | Height: | Size: 2.6 MiB |
|
After Width: | Height: | Size: 362 KiB |
|
After Width: | Height: | Size: 115 KiB |
|
After Width: | Height: | Size: 117 KiB |
|
After Width: | Height: | Size: 551 KiB |
|
After Width: | Height: | Size: 480 KiB |
|
After Width: | Height: | Size: 170 KiB |
|
After Width: | Height: | Size: 380 KiB |
|
After Width: | Height: | Size: 676 KiB |
|
After Width: | Height: | Size: 542 KiB |
|
After Width: | Height: | Size: 384 KiB |
|
After Width: | Height: | Size: 363 KiB |
|
After Width: | Height: | Size: 98 KiB |
|
After Width: | Height: | Size: 85 KiB |
|
After Width: | Height: | Size: 560 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 247 KiB |
|
After Width: | Height: | Size: 632 KiB |
|
After Width: | Height: | Size: 452 KiB |
|
After Width: | Height: | Size: 374 KiB |
|
After Width: | Height: | Size: 575 KiB |
|
After Width: | Height: | Size: 410 KiB |
|
After Width: | Height: | Size: 347 KiB |
|
After Width: | Height: | Size: 357 KiB |
|
After Width: | Height: | Size: 258 KiB |
|
After Width: | Height: | Size: 837 KiB |
|
After Width: | Height: | Size: 268 KiB |
|
After Width: | Height: | Size: 323 KiB |
|
After Width: | Height: | Size: 350 KiB |
|
After Width: | Height: | Size: 212 KiB |
|
After Width: | Height: | Size: 405 KiB |
|
After Width: | Height: | Size: 283 KiB |
|
After Width: | Height: | Size: 408 KiB |
|
After Width: | Height: | Size: 765 KiB |
|
After Width: | Height: | Size: 370 KiB |
|
After Width: | Height: | Size: 439 KiB |
|
After Width: | Height: | Size: 224 KiB |
|
After Width: | Height: | Size: 531 KiB |
|
After Width: | Height: | Size: 791 KiB |
|
After Width: | Height: | Size: 408 KiB |
|
After Width: | Height: | Size: 702 KiB |
|
After Width: | Height: | Size: 551 KiB |
|
After Width: | Height: | Size: 308 KiB |
|
After Width: | Height: | Size: 196 KiB |
|
After Width: | Height: | Size: 257 KiB |
|
After Width: | Height: | Size: 300 KiB |
|
After Width: | Height: | Size: 229 KiB |
|
After Width: | Height: | Size: 294 KiB |
|
After Width: | Height: | Size: 394 KiB |
|
After Width: | Height: | Size: 397 KiB |
|
After Width: | Height: | Size: 172 KiB |
|
After Width: | Height: | Size: 377 KiB |
|
After Width: | Height: | Size: 230 KiB |
|
After Width: | Height: | Size: 247 KiB |
|
After Width: | Height: | Size: 256 KiB |
|
After Width: | Height: | Size: 231 KiB |
|
After Width: | Height: | Size: 939 KiB |
|
After Width: | Height: | Size: 55 KiB |
|
After Width: | Height: | Size: 365 KiB |
|
After Width: | Height: | Size: 329 KiB |
|
After Width: | Height: | Size: 489 KiB |
|
After Width: | Height: | Size: 397 KiB |
|
After Width: | Height: | Size: 654 KiB |
|
After Width: | Height: | Size: 494 KiB |
|
After Width: | Height: | Size: 413 KiB |
|
After Width: | Height: | Size: 371 KiB |
|
After Width: | Height: | Size: 476 KiB |
|
After Width: | Height: | Size: 550 KiB |
|
After Width: | Height: | Size: 639 KiB |
|
After Width: | Height: | Size: 388 KiB |
|
After Width: | Height: | Size: 400 KiB |
|
After Width: | Height: | Size: 654 KiB |
|
After Width: | Height: | Size: 611 KiB |
|
After Width: | Height: | Size: 593 KiB |
|
After Width: | Height: | Size: 149 KiB |
|
After Width: | Height: | Size: 202 KiB |
|
After Width: | Height: | Size: 162 KiB |
|
After Width: | Height: | Size: 443 KiB |
|
After Width: | Height: | Size: 393 KiB |
|
After Width: | Height: | Size: 284 KiB |
|
After Width: | Height: | Size: 157 KiB |
|
After Width: | Height: | Size: 203 KiB |
|
After Width: | Height: | Size: 353 KiB |
|
After Width: | Height: | Size: 400 KiB |