# Backend Integration Details (Local)

This file documents how the Press.Zone backend is deployed and how the WordPress plugin talks to it.

SECURITY
- This file contains credentials and infrastructure details.
- It is intentionally gitignored by `plugins/multilingual-press-zone/.gitignore`.
- Keep file permissions restrictive (recommended: `chmod 600`).

Last Updated: 2026-02-14

## Host Topology

There are two relevant servers:

1) Apache reverse proxy host ("connect.sh" host)
- SSH: `root@100.109.41.8`
- Hostname: `dev01.wehost.co.il`
- Web server: Apache (`httpd`)
- Vhost file:
  - `/etc/httpd/conf.d/api.press.zone.conf`

This host terminates HTTPS for `api.press.zone` (via Cloudflare in front) and proxies selected paths to the Node API host.

2) Backend API host (Podman)
- SSH: `root@100.116.176.87`
- Hostname: `cloudpanel01`
- App user: `press-api` (use `su - press-api`)
- Backend repo path:
  - `/home/press-api/Press.Zone-Works/press-zone-backend`
- Container runtime:
  - `podman` / `podman-compose`
- Compose file:
  - `/home/press-api/Press.Zone-Works/press-zone-backend/podman-compose.yml`

API process is exposed on the host network at `http://127.0.0.1:3000` on `100.116.176.87`.

## Reverse Proxy Mapping (api.press.zone)

On `root@100.109.41.8`, in `/etc/httpd/conf.d/api.press.zone.conf`, these mappings exist:

- `/translate/` -> `http://185.151.196.109/translate/` (legacy)
- `/health` -> `http://100.116.176.87:3000/health`
- `/v1/` -> `http://100.116.176.87:3000/v1/`
- `/pricing` -> `http://100.116.176.87:3000/pricing`
- `/account/licenses` -> `http://100.116.176.87:3000/account/licenses`
- `/admin/` (static SPA) -> `/home/dev1/public_html/admin/`

Quick smoke checks:
- `curl -i https://api.press.zone/health`
- `curl -i https://api.press.zone/v1/multilingual/license/status`
- `curl -i https://api.press.zone/pricing`
- `curl -i https://api.press.zone/account/licenses`
- `curl -i https://api.press.zone/admin/`

## Backend Deployment (Podman Compose)

On `root@100.116.176.87`:

```bash
su - press-api
cd /home/press-api/Press.Zone-Works/press-zone-backend

# rebuild and restart
podman-compose -f podman-compose.yml up -d --build

# check
podman ps --filter name=presszone --format "table {{.Names}}\t{{.Status}}"
curl -i http://127.0.0.1:3000/health
```

Important env var note:
- The API container requires `JWT_ADMIN_SECRET`.
- Ensure `podman-compose.yml` passes `JWT_ADMIN_SECRET` into the `api` service.

## Admin Panel Deployment

The admin panel is deployed as a static SPA under:
- URL: `https://api.press.zone/admin/`
- Files on Apache host:
  - `/home/dev1/public_html/admin/`

Build command (local dev machine):

```bash
cd wp-content/press-zone-backend/admin-panel
VITE_API_URL='https://api.press.zone' VITE_BASE='/admin/' npm run build
```

Deploy command (from local dev machine):

```bash
rsync -az --delete wp-content/press-zone-backend/admin-panel/dist/ \
  root@100.109.41.8:/home/dev1/public_html/admin/
```

SPA routing:
- The build uses `/admin/` base.
- React Router runs with `basename={import.meta.env.BASE_URL}`.

## Admin Credentials (Production)

Admin user:
- Email: `admin@press.zone`
- Password: `VJTat6C2OcntfIiTms40qb3_tQ6nRIgQ`

Login endpoints:
- UI: `https://api.press.zone/admin/login`
- API: `POST https://api.press.zone/v1/admin/auth/login`

Example login request:

```bash
curl -s -X POST https://api.press.zone/v1/admin/auth/login \
  -H 'Content-Type: application/json' \
  -d '{"email":"admin@press.zone","password":"VJTat6C2OcntfIiTms40qb3_tQ6nRIgQ"}'
```

## Multilingual Press Zone Licensing API

Public licensing base:
- `https://api.press.zone/v1/multilingual/license`

Endpoints:
- `GET /status` (always 200; if query params are provided, returns license info)
- `POST /activate`
- `POST /deactivate`
- `POST /validate`

Tier mapping in responses (plugin expects):
- backend `starter` -> plugin `personal`
- backend `professional` -> plugin `professional`
- backend `enterprise` -> plugin `agency`

## Creating License Keys

Preferred (UI):
- Go to `https://api.press.zone/admin/licenses`
- Create license (returns key once)

Fallback (CLI inside container):

```bash
ssh root@100.116.176.87
su - press-api
podman exec -i presszone-api node - <<'NODE'
(async () => {
  const svc = require('./dist/services/multilingualLicenseService');
  const expires_at = new Date(Date.now() + 365 * 24 * 60 * 60 * 1000);
  const created = await svc.createLicense({ plan_tier: 'starter', sites_allowed: 1, expires_at });
  console.log(created.license_key);
})();
NODE
```

## Playwright Verification

Backend surface check:
- `plugins/multilingual-press-zone/tests/e2e/backend-licensing-surface.spec.js`

License activation flow:
- `plugins/multilingual-press-zone/tests/e2e/licensing-activation-flow.spec.js`
- Requires env var `MPZ_LICENSE_KEY` set to a real key.

Example:

```bash
cd wp-content/plugins/multilingual-press-zone/tests/e2e
MPZ_LICENSE_KEY='XXXX-XXXX-XXXX-XXXX' npx playwright test licensing-activation-flow.spec.js --project=chromium --project=firefox
```
