This is a Fastify + TypeScript HTTP demo application.
src/app.ts: Fastify entry plugin; autoloadssrc/pluginsandsrc/routes.src/routes/root.ts: home route.src/routes/stations/*/index.ts: station page routes (/stations/...).src/routes/api/*/index.ts: API behavior routes (/api/...).src/plugins/*.ts: shared Fastify plugins (cookies, formbody, static files, sensible).src/public/: static assets served at/public/*(HTML, JS, CSS).src/lib/: shared helpers/state (JWT helpers, in-memory stores).test/routes/*.test.ts: integration tests using Fastify inject.
Prefer adding new demos as a station + matching API module, not by growing one large route file.
npm run build:ts: compile TypeScript todist/.npm test: compile app + tests, run Node test suite with coverage (c8).npm run dev: watch TypeScript and run Fastify with reload.npm start: build and run production-style server on default host.npm run start:lan: build and run on0.0.0.0for LAN access.
- Language: TypeScript, 2-space indentation, concise semicolon-free style (match existing files).
- Route/plugin modules export a single default
FastifyPluginAsync. - Use
kebab-casedirectories for stations and API topics (e.g.,session-auth,fetch-json). - Keep UI minimal; use static assets in
src/publicinstead of inline HTML/CSS/JS where practical. - When committing, add a Co-Authored by line and state your model number
- Framework: Node’s built-in
node:test+assert. - Test behavior via
app.inject(...); assert status, headers, and payload. - Name tests by observable behavior (e.g.,
"cors preflight and allowed origin behavior"). - Add/adjust tests for every route or protocol behavior change.
- Follow existing commit style: imperative, concise summary (e.g.,
Refactor ...,Clarify ...,Enhance ...). - Keep commits focused by concern (routing, assets, tests, docs).
- PRs should include:
- what changed and why,
- affected routes/pages,
- test evidence (
npm testoutput), - screenshots for UI/station-page changes where useful.
- JWT and auth demos are educational; do not treat defaults as production-hardening.
- Prefer env vars for secrets (
DEMO_JWT_ACCESS_SECRET,DEMO_JWT_REFRESH_SECRET) in real deployments. - In-memory stores reset on restart by design.