# Reverb over WSS (HTTPS sites) – Real-time chat

If your app is served over **HTTPS** (e.g. `https://zoksh.sellzaki.local`), the browser only allows **WSS**. To get real-time chat working, use one of the following.

---

## Quick fix (recommended): Proxy WSS through your web server

**.env is already set** for this. You only need to:

1. **Add the proxy** to your HTTPS server (Nginx/Caddy) for the tenant domain.
   - **Nginx:** Copy the contents of `docs/reverb-proxy-nginx.conf` into your server block (the one with `server_name zoksh.sellzaki.local;` or your tenant domain), then reload Nginx (`sudo nginx -s reload` or restart the web server).
   - **Laravel Herd:** Herd uses Nginx; add the `location /reverb { ... }` block inside the server config for your site (e.g. edit the config Herd generated for the domain), then restart Herd or run `herd restart nginx`.
   - **Caddy:** Add `reverse_proxy /reverb/* 127.0.0.1:8080` to the block for this domain, then reload Caddy.

2. **Start Reverb** (keep it running in a terminal):
   ```bash
   php artisan reverb:start
   ```

3. **Rebuild the frontend** (so it uses the proxy URL):
   ```bash
   npm run react:build
   ```

4. Hard-refresh the app. The client will connect to `wss://zoksh.sellzaki.local/reverb/...` (port 443), and your server will proxy to Reverb on 8080.

---

## Option 1: Reverb with TLS (Herd / Valet)

If you use **Laravel Herd** or **Laravel Valet** and your site is secured (`valet secure` or similar), start Reverb with the same hostname so it uses the same certificate:

```bash
php artisan reverb:start --host=0.0.0.0 --port=8080 --hostname=zoksh.sellzaki.local
```

**.env:**

```env
VITE_REVERB_SCHEME=https
VITE_REVERB_HOST=zoksh.sellzaki.local
VITE_REVERB_PORT=8080
```

The client will connect to `wss://zoksh.sellzaki.local:8080`.

## Option 2: Proxy WSS through your web server

Run Reverb on port 8080 (no TLS), and proxy WebSocket traffic from your HTTPS server to Reverb.

1. **Reverb path** – in `.env`:
   ```env
   REVERB_SERVER_PATH=/reverb
   ```

2. **Start Reverb:**
   ```bash
   php artisan reverb:start
   ```

3. **Proxy** – add a WebSocket proxy on your HTTPS server.

   **Nginx** (e.g. in your server block for `zoksh.sellzaki.local`):
   ```nginx
   location /reverb {
       proxy_pass http://127.0.0.1:8080;
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
   }
   ```

   **Caddy** (e.g. in your `Caddyfile`):
   ```caddy
   reverse_proxy /reverb/* 127.0.0.1:8080
   ```

4. **Frontend .env:**
   ```env
   VITE_REVERB_SCHEME=https
   VITE_REVERB_HOST=zoksh.sellzaki.local
   VITE_REVERB_PORT=443
   VITE_REVERB_WS_PATH=/reverb
   ```

Then run `npm run react:build` (or restart `npm run react:dev`) so the app uses the new env.

The client will connect to `wss://zoksh.sellzaki.local/reverb/app/...` (port 443), and the server will proxy to Reverb on 8080.
