# Deploy TSS Poll on cPanel (poll.theschiffshow.tv)

Server: `server.teipen.com` (cPanel). App: Passenger Node.js. Zip: `tss-poll-v1.zip` (extract with **no** wrapper folder).

Do these steps in order. Do not overwrite any other poll app (e.g. IMC `/poll`).

## 1. Create the subdomain
1. In cPanel, open **Domains** (or **Subdomains**).
2. Create subdomain **`poll`** for domain **`theschiffshow.tv`** → host **`poll.theschiffshow.tv`**.
3. Note the document root cPanel creates (often `poll.theschiffshow.tv` or similar under your home). You will point the Node app at an **app root** that can be this folder or a sibling folder outside `public_html` if you prefer. For a root install, the app root = the subdomain’s document root.

## 2. SSL (AutoSSL)
1. Open **SSL/TLS Status** (or **Security → SSL/TLS Status**).
2. Select **`poll.theschiffshow.tv`** and run **Run AutoSSL** / **Include during AutoSSL**.
3. Wait until https://poll.theschiffshow.tv/ shows a valid certificate (usually a few minutes).

## 3. Setup Node.js App
1. Open **Setup Node.js App** (Application Manager).
2. **Create Application**:
   - **Node.js version:** 18+ (match what you use for other Node apps if possible).
   - **Application mode:** Production.
   - **Application root:** the folder where you will extract the zip (same as the subdomain docroot for a root install).
   - **Application URL:** `poll.theschiffshow.tv` (no path).
   - **Application startup file:** `app.js`
3. **Environment variables** (add before or after first start; names exact):
   - `DEFAULT_BRAND` = `theschiffshow`
   - `PRESENTER_PIN` = *(choose your own PIN; do not leave blank on the live show)*
   - Optional but recommended: `PUBLIC_URL` = `https://poll.theschiffshow.tv/`
   - Optional: `BASE_PATH` = *(leave empty / unset for subdomain root)*
4. Save / Create. Do **not** click “Run NPM Install” until the files are uploaded.

Also ensure a single Passenger process (in-memory quiz state + sql.js). On a dedicated server add to the app’s `.htaccess` or Apache include:
```
PassengerMaxPool 1
```
(or `PassengerMinInstances 1` + `PassengerMaxInstancesPerApp 1`).

## 4. Upload and extract the zip
1. Upload **`tss-poll-v1.zip`** into the **application root** (File Manager or SFTP).
2. Extract **in place** so `app.js`, `package.json`, `public/`, etc. sit **directly** in the app root — **no** wrapping `tss-poll/` folder.
3. Confirm you see at least: `app.js`, `server.js`, `quiz.js`, `package.json`, `config.json`, `public/`, `brands/`, `quizzes/`, `lib/`.
4. Do **not** upload a `data/` folder from your laptop; the app creates `data/quiz.sqlite` on first run. Keep live `data/` backed up after each show.

You can also set `DEFAULT_BRAND` / `PUBLIC_URL` / empty `PRESENTER_PIN` in `config.json`; **environment variables override** the file. Prefer setting `PRESENTER_PIN` only as an env var so it is not stored in the zip.

## 5. Run NPM Install
1. In **Setup Node.js App**, open this application.
2. Click **Run NPM Install** (uses production deps; equivalent to `npm install --omit=dev`).
3. Wait until it finishes without errors (`exceljs`, `express`, `qrcode`, `sql.js`).

## 6. Restart and smoke-test
1. Click **Restart** on the Node.js app.
2. Projector / laptop: open `https://poll.theschiffshow.tv/presenter` — enter the PIN you chose — pick **The Schiff Show Episode #22** (or another quiz) → **New session**. Confirm black/red TSS logo and footer.
3. Phone: open `https://poll.theschiffshow.tv/` (or scan the QR) — join form should show TSS branding, footer “The Schiff Show · theschiffshow.tv”.
4. Run one short question end-to-end; try **Export CSV** and **Export Slido**.

## After each live show
- Download / back up `data/quiz.sqlite` from the app root.
- Keep `PRESENTER_PIN` private.

## Notes for producers
- Correct answers in the PowerPoint deck: mark the correct choice shape with theme color **accent6** (green). Wrong choices use accent2.
- Live scoring stays speed-based **1000 → 500**; Slido-format xlsx exports use count-correct (Slido-compatible).


## v4 notes
- Install zip does **not** include `config.json` — keep your existing file (PIN). See `config.example.json` for new optional keys such as `DEFAULT_QUESTION_SECONDS` (default 20).
- Per-quiz `defaultTimeLimit` and per-question `timeLimit` still override the config default. Scoring 1000→500 tracks the same timer length.
- `.htaccess` sets `PassengerMaxPool 1` so in-memory quiz state stays on one process.
- Presenter QR: Small (~240px) / Big (~420px) / Hidden; preference saved in the browser.
- Bottom-right session dropdown is for **exports only** (not question picking). Use **Next** to move: question → results → leaderboard → next question … → final podium.


## Capacity (500+ phones)

Local load tests (SSE + join + vote) show the Node app itself is fine at **500–750** after broadcast throttle (~4/s), one JSON stringify per fan-out, and debounced sql.js saves (2s). Live cPanel/Passenger may still cap you below that:

| What to check | Where / setting names | Why it matters |
|---|---|---|
| Apache / LiteSpeed workers | `MaxRequestWorkers` (Apache) or LiteSpeed connection / max clients | Each phone keeps a long-lived SSE → one worker/connection |
| Passenger pool | `PassengerMaxPoolSize` / Application Manager max instances (often **1**) | Single Node process is OK for CPU after optimizations; pool=1 is expected |
| Passenger concurrency | `PassengerMaxRequestQueueSize`, `PassengerThreadCount` (if used) | Queueing under burst joins |
| CloudLinux LVE entry processes | **EP / Entry Processes** (cPanel → Resource Usage / CloudLinux) — often **20–100** | **SSE connections often count as entry processes** and are the usual hard cap |
| Process / memory caps | `nproc`, LVE memory (MB/PMEM), physical RAM | 750 SSE clients ~150MB RSS locally; leave headroom |
| Proxy timeouts | Apache `Timeout`, `ProxyTimeout`; LiteSpeed idle timeout | Idle SSE can be cut if too short (keep ≥60s; app sends 20s pings) |

**If EP limits block SSE:** phones can fall back to short polling `GET /api/quiz/state` (TSS) or `GET /api/state` (PAVE) every 1–2s instead of `/quiz-events` / `/events`. That trades fan-out efficiency for fewer long-lived connections.

Ask the host to report current **EP limit**, **MaxRequestWorkers** (or LS equiv.), and confirm SSE is not being buffered (`X-Accel-Buffering: no` / no gzip on event streams — `.htaccess` already hints this).
