# BulkMailer Pro — cPanel Deployment Guide

This folder contains everything you need to run BulkMailer Pro on cPanel.

---

## Option A — Single Node.js App (Recommended)

Use this if your cPanel host supports **Node.js Selector** (most modern cPanel hosts do).

### 1. Create a PostgreSQL database
In cPanel → PostgreSQL Databases, create a database and user. Note the connection details.

### 2. Upload files
Upload the **entire contents** of this `cpanel-dist/` folder to your Node.js app directory
(usually something like `/home/youruser/nodevenv/myapp/`).

### 3. Set environment variables
In cPanel → Node.js Selector → your app → Environment Variables, add:

| Variable | Value |
|---|---|
| `DATABASE_URL` | `postgresql://user:pass@localhost:5432/dbname` |
| `SESSION_SECRET` | Any long random string (32+ chars) |
| `SERVE_STATIC` | `true` |
| `STATIC_DIR` | `public` |
| `SITE_URL` | `https://yourdomain.com` |
| `NODE_ENV` | `production` |
| `ADMIN_PASSWORD` | Your secure admin password |

### 4. Set startup file
In Node.js Selector, set the **Application startup file** to: `dist/index.mjs`

### 5. Install dependencies and start
```bash
npm install --omit=dev
npm start
```

### 6. Run database migrations (first time only)
The database schema is automatically applied on first request — no manual migration needed.

---

## Option B — Frontend Only (Static Files)

If you only want to host the **frontend** on cPanel and run the API server separately:

1. Upload the contents of `public/` to your `public_html/` folder.
2. The `.htaccess` file inside `public/` handles React Router routing — keep it there.
3. The frontend currently talks to `/api/*` on the same domain. If your API is on a different
   subdomain (e.g. `api.yourdomain.com`), you'll need to set `VITE_API_BASE_URL` before building.

---

## After Deployment

1. Visit `https://yourdomain.com/admin` and log in with your `ADMIN_PASSWORD`.
2. Go to **Settings** and fill in:
   - **Site URL** — your full domain (required for password reset emails)
   - **Crypto wallet addresses** — for the billing page
   - **Resend API key** — for password reset emails (free at resend.com)
3. Register your first user account and start using the platform.

---

## Troubleshooting

- **White screen / 404 on refresh** — make sure `.htaccess` is in `public/` and mod_rewrite is enabled.
- **API calls failing** — check `DATABASE_URL` and `SESSION_SECRET` are set correctly.
- **Password reset links go to wrong URL** — set `SITE_URL` in admin settings.
