{"slug":"operations/CLOUDFLARE_DEPLOYMENT","title":"Cloudflare Workers Deployment","section":"operations","sectionLabel":"Operations","status":"unclassified","type":"document","path":"operations/CLOUDFLARE_DEPLOYMENT.mdx","bytes":3295,"description":null,"updated":null,"source":"integratewise/Integratewise-docs-wiki","content":"\n## Architecture\n\nIntegrateWise backend runs on Cloudflare Workers, organized as:\n\n1. **Gateway** (entrypoint) → routes to all services via internal bindings\n2. **Core Services** (pipeline, spine, connector, intelligence, knowledge, workflow, hermes, govern, act)\n3. **MCP Services** (provider-management, integration-management for auth)\n4. **Next.js Frontend** (apps/web) → deployed to Vercel or Cloudflare Pages, calls Gateway APIs\n\n## Deployment\n\n### Prerequisites\n\n1. Install Wrangler CLI: `pnpm add -D wrangler@latest`\n2. Authenticate: `pnpm exec wrangler login`\n3. Verify account_id in `services/gateway/wrangler.toml`\n\n### Deploy Services (Staging)\n\n```bash\npnpm run deploy:staging\n# or manually per service:\ncd services/gateway && pnpm exec wrangler deploy --env staging\ncd services/pipeline && pnpm exec wrangler deploy --env staging\n# etc.\n```\n\n### Deploy Services (Production)\n\n```bash\npnpm run deploy:prod\n```\n\n### Environment Variables\n\nSecrets are configured per environment in `wrangler.toml` and stored in Cloudflare Secrets Manager:\n\n```bash\n# Set secrets in Cloudflare\npnpm exec wrangler secret put SUPABASE_URL --env staging\npnpm exec wrangler secret put SUPABASE_SERVICE_ROLE_KEY --env staging\npnpm exec wrangler secret put DATABASE_URL --env staging\n```\n\n## Service Bindings\n\nThe Gateway binds all services internally:\n\n```toml\n[services]\npipeline = { binding = \"PIPELINE\" }\nspine = { binding = \"SPINE\" }\nconnector = { binding = \"CONNECTOR\" }\nintelligence = { binding = \"INTELLIGENCE\" }\n# etc.\n```\n\nServices are NOT directly accessible; all requests route through the Gateway.\n\n## Frontend Deployment\n\n### Option 1: Cloudflare Pages (static export)\n\n```bash\n# Build with static export enabled\nSTATIC_EXPORT=1 pnpm run build --filter @integratewise/web\n# Deploy to Cloudflare Pages (automatic via Git)\n```\n\n### Option 2: Vercel (Server Mode)\n\n```bash\n# Deploy as-is (server mode for Route Handlers + dynamic RSC)\npnpm run deploy --filter @integratewise/web\n# Gateway URL configured in NEXT_PUBLIC_API_BASE_URL\n```\n\n## Routing\n\n- **Gateway URL**: `https://gateway.{env}.integratewise.ai/`\n- **Frontend URL** (Vercel): `https://integratewise.ai/`\n- **Frontend URL** (Cloudflare Pages): `https://pages.{env}.integratewise.ai/`\n\nAll frontend requests to `/api/*` proxied to Gateway via environment variable `NEXT_PUBLIC_API_BASE_URL`.\n\n## Verification\n\n```bash\n# Health check\ncurl https://gateway.staging.integratewise.ai/health\n\n# List apps (marketplace)\ncurl https://gateway.staging.integratewise.ai/api/marketplace/apps \\\n  -H \"Authorization: Bearer YOUR_JWT\"\n\n# Check service bindings\npnpm exec wrangler tail --env staging\n```\n\n## Rollback\n\nEach deploy creates a new version. Rollback via:\n\n```bash\npnpm exec wrangler deployments list\npnpm exec wrangler rollback --version YOUR_VERSION\n```\n\n## Notes\n\n- **No static export on production**: Authenticated product routes require server mode. Remove `STATIC_EXPORT=1` for production builds.\n- **D1 Database**: Gateway reads tenant/user records from D1 (integratewise-spine-cache). Ensure D1 is replicated across regions for HA.\n- **Rate Limiting**: Configured in Gateway; adjust in `services/gateway/src/lib/rate-limit.ts`.\n- **CORS**: Configured in Gateway; update `CORS_ORIGINS` as needed.\n"}