# PrimeDT Coach Portal with Motion recordings – Deployment Instructions (7 Nov 2026)

This is the built coach portal with **both open pull requests combined**:

- **PR #2** (`feature/demos-tab`, up to `a5d87f3`): Group B hardening (security headers,
  react-router 7.18), 404/429 handling, report-only CSP for `app.heart-rv.in:3030`, Demos tab.
- **PR #3** (`feature/motion-recordings-panel`, `3b1ec31`): the Motion recordings panel.

Built from a local merge of PR #3 into PR #2 (merge commit `85f1a7e`, no conflicts, not pushed).
It is a static site: copy `dist/` to the web server.

| Item | Value |
| --- | --- |
| API server built in | `https://app.heart-rv.in:3030` |
| Built with | `VITE_API_URL=https://app.heart-rv.in:3030 npm run build` |
| Type check | `tsc -b` clean |

## Before you deploy

- **The Motion panel needs the server module** (Motion_Server_Module_v0.1.1). Until it is
  deployed on `app.heart-rv.in:3030`, the panel shows "Motion recordings are not available
  on this server yet." Everything else on the portal works as before.
- **Coaches need `canViewAthlete`** written in the server module, or the panel shows
  "You do not have access to this trainee's motion recordings."
- **Merge order on GitHub:** merge PR #2 first, then PR #3 (it merges cleanly). Building
  `master` after both gives the same result as this package. Deploying a build of PR #3
  alone would drop PR #2's hardening, CSP and Demos tab.

## Deploy

1. Back up the files currently served for the portal.
2. Replace them with the contents of `dist/`: `index.html`, `assets/`, `images/`,
   `favicon.png` **and the hidden `.htaccess`** (from the repo's `public/` folder).
   It sends unknown paths to `index.html`, so a reload on `/trainees/42` works, and it
   caches `assets/` long term but not `index.html`. It needs Apache `mod_rewrite`,
   `mod_headers` and `AllowOverride`.
   - **nginx instead of Apache:** `.htaccess` is ignored; add
     `location / { try_files $uri $uri/ /index.html; }`.
3. Remove old files from `assets/` only after the new `index.html` is live.
4. Hard-refresh the browser (Ctrl+F5) once after deploying.
5. Open the portal, sign in as a coach, open a trainee. The Motion recordings panel is below
   the resting heart rate card.

## A different API server (for example the test server)

The server address is fixed at build time. To point the portal at another server, rebuild:

```
git checkout master        # after PR #2 and PR #3 are merged
npm ci
VITE_API_URL=https://<test server>:3030 npm run build
```

The test server must allow the portal's origin in its CORS settings, as the live server does.
Also add the test server to `connect-src` in `public/.htaccess` (the CSP), or the browser
reports it as a violation (report-only today, blocked once the CSP is enforced).

## Rollback

Put back the files from step 1, then hard-refresh. No server or database change is involved.

## Checks done

- Merge of PR #3 into PR #2: no conflicts.
- `npx tsc -b`: no errors.
- `npm run build`: succeeds. The three CSS syntax warnings were already on `master`.
- Built output contains the Motion panel and the Demos tab; the only API host is `app.heart-rv.in:3030`.
- PR #3 alone was run locally against the live server, with the motion endpoints served by the
  server module locally: the panel listed five real phone recordings. The combined build has
  not been run in a browser yet.
