Documentation Index
Fetch the complete documentation index at: https://mintlify.com/MatthewSabia1/SubPirate-Pro/llms.txt
Use this file to discover all available pages before exploring further.
Overview
SubPirate Pro is optimized for deployment on Vercel using serverless functions. The architecture includes:- Frontend: Static SPA built with Vite (served from
dist/) - API: Serverless functions in
api/directory - Cron jobs: Automated campaign dispatch every minute
Architecture
Dual-Server Design
SubPirate Pro uses different server implementations for local vs. production:- Local development: Express monolith (
server.js) with all routes inline - Vercel production: Serverless functions in
api/directory that mirror Express routes
- Fast local development with hot reload
- Scalable production deployment with automatic scaling
- Shared business logic via
api/_lib/utilities
Serverless Functions
Theapi/ directory contains Vercel serverless functions:
Deployment Steps
Configure environment variables
Set all required environment variables in Vercel dashboard or via CLI:
Complete environment variable list
Complete environment variable list
Deploy to preview
Deploy to a preview environment to test before production:This creates a unique preview URL for testing.
Vercel Configuration
Thevercel.json file configures the deployment:
vercel.json
Build Configuration
- buildCommand: Runs
npm run buildwhich type-checks and builds the Vite SPA - outputDirectory: Static files output to
dist/directory
Cron Jobs
The cron configuration runs campaign dispatch every minute:- Fetches all campaigns scheduled to run
- Pairs Reddit accounts with target subreddits
- Submits posts via Reddit API
- Records results in
campaign_runsandcampaign_run_attemptstables
Cron Authentication
Protect your cron endpoint with a secret:.env
x-cron-secret header:
.env
URL Rewrites
Rewrites handle routing:/health→/api/health- Health check endpoint- All non-API routes →
/index.html- SPA fallback for client-side routing
Environment Variables
Required Variables
These variables are required for deployment:| Variable | Description |
|---|---|
SUPABASE_URL | Supabase project URL |
SUPABASE_ANON_KEY | Supabase anonymous key |
OPENROUTER_API_KEY | OpenRouter API key for LLM analysis |
REDDIT_CLIENT_ID | Reddit OAuth app client ID |
REDDIT_CLIENT_SECRET | Reddit OAuth app secret |
REDDIT_USER_AGENT | Reddit API user agent string |
TOKEN_ENCRYPTION_KEY | Base64-encoded 32-byte key for AES-256-GCM |
APP_ORIGIN | Your app’s origin (e.g., https://app.example.com) |
CORS_ORIGINS | Comma-separated allowed origins |
Optional Variables
| Variable | Description | Default |
|---|---|---|
SUPABASE_SERVICE_ROLE_KEY | Service role key (for admin operations) | None |
SPEAKEASY_PASSWORD | Password for speakeasy access endpoints | None |
CAMPAIGN_SCHEDULER_ENABLED | Enable campaign scheduler | true |
CAMPAIGN_MAX_WORKERS | Max concurrent campaign workers | 1 |
CRON_SECRET | Secret for cron authentication | None |
CRON_IP_ALLOWLIST | Comma-separated IP allowlist | None |
REDDIT_REDIRECT_URI | Override Reddit OAuth callback URI | Computed |
Monitoring & Debugging
Vercel Logs
View real-time logs in Vercel dashboard:- Go to your project in Vercel
- Click “Logs” in the top navigation
- Filter by function, status code, or search term
Function Metrics
Monitor serverless function performance:- Invocations: Number of function calls
- Duration: Average execution time
- Errors: Failed invocations
- Cold starts: First invocation latency
Health Check
Verify your deployment is healthy:Troubleshooting
Build failures
Problem: Build fails with TypeScript errors Solution: Run type-check locally first:Environment variable issues
Problem: API calls fail with authentication errors Solution: Verify environment variables are set:CORS errors
Problem: Browser shows CORS errors Solution: EnsureCORS_ORIGINS includes your domain:
Cron jobs not running
Problem: Campaigns not dispatching automatically Solution:- Verify you’re on a Vercel Pro plan (required for cron)
- Check cron logs in Vercel dashboard
- Manually trigger:
curl https://your-domain.com/api/internal/campaigns/dispatch -H "x-cron-secret: your-secret"
Function timeouts
Problem: Serverless functions timeout (10s hobby, 60s pro) Solution:- Optimize long-running operations
- Use async/await properly
- Consider splitting into multiple requests
- Upgrade to Pro for 60s timeout
Non-Vercel Deployment
To deploy on other platforms using the Express server:Configure environment
Set all required environment variables (same as Vercel, minus Vercel-specific variables).
You’ll need to set up your own cron job for campaign dispatch if not using Vercel cron.
Next Steps
Supabase Setup
Configure your Supabase project
Local Development
Set up local environment