# WhatApp Pro — Server Deployment

## 1. Upload
Upload this entire folder to your server, e.g. `/home/youruser/whatapp`.

## 2. Install dependencies (run ON the server, not locally)
```
cd whatapp/server
npm install --omit=dev
```
This must run on the Linux server itself so npm fetches Linux-native binaries
(the node_modules on the machine that built this zip are Windows-only and
were deliberately excluded).

WhatsApp connectivity needs a real Chrome/Chromium on the server:
```
sudo apt-get install -y chromium-browser   # Debian/Ubuntu
# or: sudo yum install -y chromium          # CentOS/AlmaLinux
```

## 3. Configure secrets
Edit `.env` (already included, pre-filled with placeholders):
- Set `ADMIN_PASSWORD` to a real password — this is your dashboard login.
- Set `PORT` if 5002 is already in use.
- Optionally set `GBP_CLIENT_ID` / `GBP_CLIENT_SECRET` (see .env.example)
  if you want a shared Google OAuth app across all businesses.

## 4. Start the server
```
npm install -g pm2
cd whatapp/server
pm2 start server.js --name whatapp-pro --env production
pm2 save
pm2 startup   # follow the printed command to enable start-on-boot
```
The frontend is served automatically from `../dist` (same origin as the
API), so once this is running, the whole app is reachable at
`http://your-server-ip:5002/`.

## 5. Point your domain at it
Pick whichever your panel supports:

**A. Direct reverse proxy (Nginx)** — put your domain in front of port 5002:
```nginx
server {
    listen 80;
    server_name yourdomain.com;
    location / {
        proxy_pass http://127.0.0.1:5002;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}
```
Then get HTTPS with `certbot --nginx`.

**B. Locked-down panel (CyberPanel/OpenLiteSpeed without reverse-proxy access)**
Use the `dist/proxy.php` trick already in this project: point your domain's
document root at `dist/`, and add a rewrite rule sending `/api/*` requests
to `proxy.php?path=...`, which forwards to `http://127.0.0.1:5002/api/...`.
Edit the `$backend_port` value at the top of `dist/proxy.php` if you changed
`PORT` above.

## First login
Username: `admin`, password: whatever you set as `ADMIN_PASSWORD` in .env.
If you forgot to set it, the server auto-generates one on first boot and
prints it to the console / writes it to `ADMIN_CREDENTIALS.txt` next to
server.js — check there.
