Skip to content

Hướng dẫn Triển khai (Deployment)

Thông tin nhanh

  • 5 deployment targets: API (Worker), Admin (Pages), Landing (Pages), Portal (Pages), Affiliate (Pages)
  • Database: node run-migration.mjs chạy 30 migration files
  • MCP Server: Local stdio process kết nối với OpenFang

Xem thêm: Kiến trúc · Database

Tổng quan Deployment

1. Database Migrations

bash
node run-migration.mjs

Script đọc tuần tự 30+ files .sql trong schema/ và execute qua Neon.

:::caution Một số files cùng prefix (016, 017, 019) — script chạy alphabetical. Đảm bảo seed files chạy sau schema tương ứng. :::

2. Deploy API (Cloudflare Worker)

bash
cd api
npx wrangler deploy

Env vars cần set trong wrangler.toml hoặc Cloudflare dashboard:

VariableMô tả
DATABASE_URLNeon PostgreSQL connection string
JWT_SECRETSecret cho JWT signing
ADMIN_ORIGINCORS whitelist (comma-separated domains)

3. Deploy Admin (Cloudflare Pages)

bash
cd admin
npm run build
# Upload dist/ lên Cloudflare Pages

Custom domain: app.salehay.com

4. Deploy Landing (Cloudflare Pages)

bash
cd landing
npm run build
# Upload dist/ lên Cloudflare Pages

Custom domain: salehay.com

5. Deploy Portal (Cloudflare Pages)

bash
cd portal
npm run build
# Upload dist/ lên Cloudflare Pages

Custom domain: portal.salehay.com

6. Deploy Affiliate Portal (Cloudflare Pages)

bash
cd aff
npm run build
# Upload dist/ lên Cloudflare Pages

Custom domain: aff.salehay.com

7. MCP Server Setup

Chạy local, kết nối với agent platform qua stdio:

bash
cd mcp-server
CRM_BASE_URL=https://api.salehay.com CRM_AGENT_TOKEN=agent_xxx node index.js

OpenFang Config

toml
[mcp.salehay-crm]
command = "node"
args = ["/path/to/mcp-server/index.js"]
env.CRM_BASE_URL = "https://api.salehay.com"
env.CRM_AGENT_TOKEN = "agent_xxx"

OpenClaw Config

json
{
  "mcpServers": {
    "salehay-crm": {
      "command": "node",
      "args": ["/path/to/mcp-server/index.js"],
      "env": {
        "CRM_BASE_URL": "https://api.salehay.com",
        "CRM_AGENT_TOKEN": "agent_xxx"
      }
    }
  }
}

8. OpenFang HAND Setup

bash
cp openfang-hand/HAND.toml ~/.openfang/hands/crm-lead-gen/HAND.toml
cp -r skills/crm-operations ~/.openfang/skills/
cp -r skills/crm-outreach ~/.openfang/skills/
cp -r skills/crm-analytics ~/.openfang/skills/

TIP

Dùng secret manager: openfang secret set CRM_AGENT_TOKEN <token>. Không lưu token trong HAND.toml.

Checklist Pre-Deploy

  • [ ] Database migrations chạy thành công (30 files)
  • [ ] API Worker deploy, env vars đã set
  • [ ] Admin build pass, deploy Pages
  • [ ] Landing build pass, deploy Pages
  • [ ] Portal build pass, deploy Pages
  • [ ] Affiliate Portal build pass, deploy Pages
  • [ ] Agent Token đã tạo trong Admin → Settings
  • [ ] MCP Server kết nối được API
  • [ ] Custom domains đã cấu hình DNS

🔒 Internal Documentation — Dev Team Only