# How to run Room with Apache and Docker

This guide runs MongoDB and the API in Docker, then serves https://meet.mystudyplanner.in with Apache. Camera and microphone only work on that HTTPS address.

The server already hosts other sites, including `live.mystudyplanner.in` and `gitlab.mystudyplanner.in`. Leave those virtual hosts enabled. This app is a separate site. DNS for `meet.mystudyplanner.in` must point at this server before the certificate step.

## 1. Install Docker

Install Docker Engine and the Compose plugin, then confirm both commands work:

```bash
docker --version
docker compose version
```

## 2. Get the code

```bash
git clone <your-repo-url> videocall
cd videocall
```

## 3. Set the API for this server

Open `docker-compose.yml`. Change the `server` service before the first start:

- Set `CLIENT_ORIGIN` to `https://meet.mystudyplanner.in` with no slash at the end.
- Replace `JWT_ACCESS_SECRET` and `JWT_REFRESH_SECRET` with two different values from `openssl rand -base64 32`.
- Bind the API to this machine only. Apache is the public entry:

```yaml
ports:
  - "127.0.0.1:4000:4000"
```

- Delete the `ports` section under `mongo`. The API uses `mongodb://mongo:27017/videocall` inside Docker. A published `27017` exposes the database.

Optional values go in the same `environment` block. Names match `server/.env.example`.

| Name | Purpose |
| --- | --- |
| `STUN_URL` | STUN server. The default is `stun:stun.l.google.com:19302`. |
| `TURN_URL`, `TURN_USERNAME`, `TURN_CREDENTIAL` | TURN relay. Required when two people cannot connect directly. |
| `RATE_LIMIT_WINDOW_MS`, `RATE_LIMIT_MAX` | Cap for all API requests. `RATE_LIMIT_MAX=0` turns it off. |
| `AUTH_RATE_LIMIT_WINDOW_MS`, `AUTH_RATE_LIMIT_MAX` | Cap for login, signup, and guest join. |
| `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET`, `GOOGLE_REDIRECT_URI` | Google sign-in. Leave them unset to keep it off. |

`GOOGLE_REDIRECT_URI` must be `https://meet.mystudyplanner.in/api/auth/google/callback`.

## 4. Start MongoDB and the API

From the repository root. The first request can fail if it arrives while MongoDB is still starting. Run `curl` again after `docker compose ps` shows the server as healthy or up.

```bash
cd /home/www/html/videocall
docker compose up -d --build
docker compose ps
curl -fsS http://127.0.0.1:4000/api/health
```

`curl` prints `{"ok":true}` when the API is up. If it still fails, read `docker compose logs server`.

`deploy/start.sh` does this start and the health check together. It prints a success line when both the API and `https://meet.mystudyplanner.in/api/health` respond, and it exits with an error when they do not.

```bash
sudo bash /home/www/html/videocall/deploy/start.sh
```

## 5. Build the website

Install Node.js 20 or newer, then build the client. The page calls `/api` and `/socket.io` on the same host, so the build does not need an API address.

Run this from the repository root, `/home/www/html/videocall`, not from `client`. Apache serves `client/dist` directly.

```bash
cd /home/www/html/videocall/client
npm install --legacy-peer-deps
npm run build
```

For Google sign-in, create `client/.env.production` with `VITE_GOOGLE_AUTH=true` before `npm run build`.

## 6. Enable the Apache site

```bash
cd /home/www/html/videocall
sudo a2enmod proxy proxy_http proxy_wstunnel rewrite ssl headers
sudo cp deploy/meet.mystudyplanner.in.conf /etc/apache2/sites-available/meet.mystudyplanner.in.conf
sudo a2ensite meet.mystudyplanner.in.conf
sudo apache2ctl configtest
sudo systemctl reload apache2
sudo certbot certonly --webroot -w /home/www/html/videocall/client/dist -d meet.mystudyplanner.in
sudo cp deploy/meet.mystudyplanner.in-le-ssl.conf /etc/apache2/sites-available/meet.mystudyplanner.in-le-ssl.conf
sudo a2ensite meet.mystudyplanner.in-le-ssl.conf
sudo apache2ctl configtest
sudo systemctl reload apache2
```

Enable the HTTP site first. The SSL file points at `/etc/letsencrypt/live/meet.mystudyplanner.in/`, and Apache will not load it until Certbot has created those files.

`deploy/meet.mystudyplanner.in-le-ssl.conf` sends `/api/` to `http://127.0.0.1:4000/api/`. An `Upgrade: websocket` request for `/socket.io/` goes to `ws://127.0.0.1:4000`, and every other Socket.IO request goes to `http://127.0.0.1:4000`. The site files live in `/home/www/html/videocall/client/dist`. Unknown paths fall back to `index.html`, so `/meet/...` still opens the app. Do not add a `ProxyPass "/"` rule. That would send the website to port 4000 and hide the built files.

## 7. Check the running site

Open https://meet.mystudyplanner.in. Create a meeting, join from a second browser, and confirm the camera turns on. Both browsers must use the `https` address.

Calls between different networks also need the `TURN_*` values from step 3. Restart the API after adding them:

```bash
docker compose up -d server
```

## Update a later version

```bash
cd /home/www/html/videocall
git pull
docker compose up -d --build
cd client && npm install --legacy-peer-deps && npm run build
```

MongoDB data stays in the `mongo-data` volume. `docker compose down -v` deletes that volume.
