# Hosting the `backend` (NestJS API) on cPanel

The `backend/` folder is a **NestJS** API. It runs as a **Node.js server** (not static hosting).

## What you need

- Node.js **18+** (20 recommended)
- cPanel **Setup Node.js App** (or any VPS / Node hosting)
- A database (MySQL is commonly used here; Prisma is in this repo)

## Build & run commands (from `backend/`)

This repo uses:

- `npm run build` → `nest build` (outputs `dist/`)
- `npm run start` → `nest start`

On production hosting you typically do:

```bash
npm install
npm run build
npm run start
```

## Recommended: Build on the server (best for cPanel)

1. Upload the **entire `backend/` folder** to the server (zip → upload → extract).
2. In cPanel open **Setup Node.js App** and create an app:
   - **Application root**: uploaded `backend` directory
   - **Node version**: 18+ / 20
3. Add environment variables in the cPanel Node app screen (see below).
4. Open terminal and run:

```bash
npm install
npm run build
```

5. Start the app (either via cPanel “Run NPM Install / Restart App” UI or a start command):

```bash
npm run start
```

## Environment variables (minimum)

Exact variables depend on your config, but these are typical and commonly required:

- **`NODE_ENV=production`**
- **`PORT`**: cPanel usually injects this automatically (don’t hardcode unless your host requires it)
- **`DATABASE_URL`**: Prisma connection string  
  Example (MySQL): `mysql://USER:PASSWORD@HOST:3306/DBNAME`

If you’re using Redis / JWT / Razorpay etc, also set the matching secrets you already use locally.

### Exchange-rate feature (USD→INR)

If you want to control caching / fallback:

- **`EXCHANGE_CACHE_MS`** (default 3600000)
- **`EXCHANGE_USD_INR_FALLBACK`** (default 83)

## Prisma (database) notes

This repo includes Prisma (`@prisma/client`, `prisma`).

- If you deploy to a fresh server, you may need to run:

```bash
npx prisma generate
```

- For schema changes/migrations: prefer running migrations intentionally (and carefully).  
This repo has `prisma:migrate` script but it’s `prisma migrate dev` (dev-oriented). On production you usually use `prisma migrate deploy`.

If you tell me which DB you’re using (MySQL on cPanel, PlanetScale, etc.), I’ll give you the exact safe commands.

## Domain setup (API URL)

You usually host the API on a subdomain, for example:

- `api.yourdomain.com` → points to the cPanel Node app

Then set in both frontends:

- `panel`: `NEXT_PUBLIC_API_URL=https://api.yourdomain.com`
- `god-panel`: `NEXT_PUBLIC_API_URL=https://api.yourdomain.com`

## Quick verification

After starting the backend:

- Open `GET /website-content` from a browser (or Postman)
- Open `GET /exchange/usd-inr` and confirm it returns `{ rate: ... }`
- Open the panel and check DevTools → Network → no CORS errors

