Skip to main content

Production Environment Setup

Step-by-step guide to configure Dashtray for production deployment.

Overview

This guide covers:
  1. Convex production deployment
  2. Cloudflare Pages project setup
  3. Environment variable configuration
  4. Custom domain and SSL setup
  5. DodoPayments webhook configuration

Prerequisites Checklist

  • Convex account created
  • Cloudflare account created
  • DodoPayments account created
  • Resend account created
  • Domain name purchased (optional)
  • GitHub repository set up
  • Local development environment working

Step 1: Configure Convex Production

1.1 Create Production Deployment

# Deploy to production
npx convex deploy --prod
This creates a new production deployment and outputs:
  • Deployment URL: https://happy-animal-123.convex.cloud
  • Site URL: https://happy-animal-123.convex.site
Save these URLs - you’ll need them later.

1.2 Set Production Environment Variables

# Application URL (use your actual domain)
npx convex env set SITE_URL https://dashtray.com --prod

# Generate and set authentication secret
npx convex env set BETTER_AUTH_SECRET $(openssl rand -base64 32) --prod

# Generate and set encryption key
npx convex env set MASTER_ENCRYPTION_KEY $(openssl rand -hex 32) --prod
IMPORTANT: Save the MASTER_ENCRYPTION_KEY in a secure location (password manager, encrypted file). You’ll need it if you ever need to migrate data.

1.3 Configure Email (Resend)

  1. Log in to Resend Dashboard
  2. Go to API Keys
  3. Create a new API key named “Dashtray Production”
  4. Copy the API key
npx convex env set RESEND_API_KEY re_your_production_key --prod
npx convex env set RESET_EMAIL_FROM noreply@dashtray.com --prod

1.4 Verify Domain in Resend

  1. In Resend dashboard, go to Domains
  2. Click “Add Domain”
  3. Enter your domain (e.g., dashtray.com)
  4. Add the provided DNS records to your domain:
    • TXT record for verification
    • MX records for receiving
    • DKIM records for authentication
  5. Wait for verification (can take up to 48 hours)

1.5 Configure OAuth (Optional)

Google OAuth

  1. Go to Google Cloud Console
  2. Create a new project: “Dashtray Production”
  3. Enable Google+ API
  4. Go to Credentials → Create Credentials → OAuth 2.0 Client ID
  5. Application type: Web application
  6. Name: “Dashtray”
  7. Authorized redirect URIs:
    https://your-deployment.convex.site/api/auth/callback/google
    https://dashtray.com/api/auth/callback/google
    
  8. Copy Client ID and Client Secret
npx convex env set GOOGLE_CLIENT_ID your_client_id --prod
npx convex env set GOOGLE_CLIENT_SECRET your_client_secret --prod

GitHub OAuth

  1. Go to GitHub Settings → Developer settings
  2. Click “New OAuth App”
  3. Application name: “Dashtray”
  4. Homepage URL: https://dashtray.com
  5. Authorization callback URL:
    https://your-deployment.convex.site/api/auth/callback/github
    
  6. Copy Client ID and Client Secret
npx convex env set GITHUB_CLIENT_ID your_client_id --prod
npx convex env set GITHUB_CLIENT_SECRET your_client_secret --prod

1.6 Verify Convex Configuration

# List all environment variables
npx convex env list --prod

# Should show:
# SITE_URL
# BETTER_AUTH_SECRET
# MASTER_ENCRYPTION_KEY
# RESEND_API_KEY
# RESET_EMAIL_FROM
# (Optional) GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET
# (Optional) GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET

Step 2: Configure DodoPayments

2.1 Create DodoPayments Account

  1. Sign up at DodoPayments
  2. Complete business verification
  3. Set up payment methods

2.2 Get API Credentials

  1. Go to Settings → API Keys
  2. Create a new API key for production
  3. Copy the API key (starts with dp_live_)
npx convex env set DODO_PAYMENTS_API_KEY dp_live_your_key --prod
npx convex env set DODO_PAYMENTS_ENVIRONMENT production --prod

2.3 Create Products and Prices

  1. Go to Products in DodoPayments dashboard
  2. Create products for each tier:
Pro Plan:
  • Name: “Dashtray Pro”
  • Price: $69/month
  • Billing: Recurring monthly
  • Trial: 14 days
Scale Plan:
  • Name: “Dashtray Scale”
  • Price: $199/month
  • Billing: Recurring monthly
  • Trial: 14 days
Agency Plan:
  • Name: “Dashtray Agency”
  • Price: $599/month
  • Billing: Recurring monthly
  • Trial: 14 days
  1. Note the Product IDs and Price IDs

2.4 Configure Webhook

  1. In DodoPayments dashboard, go to Webhooks
  2. Click “Add Endpoint”
  3. URL: https://your-deployment.convex.site/api/webhooks/dodo
  4. Events to send:
    • subscription.created
    • subscription.updated
    • subscription.canceled
    • payment.succeeded
    • payment.failed
  5. Copy the webhook signing secret
npx convex env set DODO_PAYMENTS_WEBHOOK_SECRET whsec_your_secret --prod

2.5 Test Webhook

  1. In DodoPayments dashboard, go to Webhooks
  2. Click on your webhook endpoint
  3. Click “Send test webhook”
  4. Verify it shows as successful
  5. Check Convex logs: npx convex logs --prod

Step 3: Set Up Cloudflare Pages

3.1 Create Cloudflare Pages Project

Option A: Connect Git Repository

  1. Go to Cloudflare Dashboard
  2. Navigate to Pages
  3. Click “Create a project”
  4. Click “Connect to Git”
  5. Authorize Cloudflare to access your GitHub/GitLab
  6. Select your repository
  7. Configure build settings:
    • Project name: dashtray
    • Production branch: main
    • Build command: pnpm build
    • Build output directory: .svelte-kit/cloudflare
    • Root directory: /
    • Node version: 18

Option B: Direct Upload (Manual)

  1. Build locally:
    pnpm build
    
  2. Deploy with Wrangler:
    wrangler pages deploy .svelte-kit/cloudflare --project-name=dashtray
    

3.2 Configure Environment Variables

In Cloudflare Pages project settings, add:
PUBLIC_CONVEX_URL=https://your-deployment.convex.cloud
PUBLIC_CONVEX_SITE_URL=https://your-deployment.convex.site
SITE_URL=https://dashtray.com
Note: These must match the URLs from Step 1.1 and the SITE_URL from Step 1.2.

3.3 Configure Build Settings

  1. Go to Settings → Builds & deployments
  2. Set Node.js version: 18
  3. Enable “Automatic deployments” for main branch
  4. Set build timeout: 20 minutes

3.4 Test Deployment

  1. Trigger a deployment (push to main or manual deploy)
  2. Wait for build to complete
  3. Visit the Cloudflare Pages URL (e.g., dashtray.pages.dev)
  4. Verify the site loads correctly

Step 4: Configure Custom Domain and SSL

4.1 Add Custom Domain

  1. In Cloudflare Pages project, go to “Custom domains”
  2. Click “Set up a custom domain”
  3. Enter your domain: dashtray.com
  4. Click “Continue”

4.2 Configure DNS

Cloudflare will provide DNS instructions. You have two options:
  1. In Cloudflare dashboard, go to Websites
  2. Click “Add a site”
  3. Enter your domain
  4. Choose a plan (Free is fine)
  5. Cloudflare will provide nameservers
  6. Update nameservers at your domain registrar
  7. Wait for DNS propagation (up to 48 hours)

Option B: Use CNAME Record

  1. In your domain registrar’s DNS settings
  2. Add a CNAME record:
    • Name: @ (or leave blank for root domain)
    • Value: dashtray.pages.dev
    • TTL: Automatic or 3600
  3. Add a CNAME record for www:
    • Name: www
    • Value: dashtray.pages.dev
    • TTL: Automatic or 3600

4.3 Enable SSL

SSL is automatic with Cloudflare:
  1. Certificate is provisioned automatically
  2. Wait 5-10 minutes for activation
  3. Verify HTTPS works: https://dashtray.com

4.4 Configure SSL Settings

  1. In Cloudflare dashboard, go to SSL/TLS
  2. Set SSL/TLS encryption mode: Full (strict)
  3. Enable “Always Use HTTPS”
  4. Enable “Automatic HTTPS Rewrites”
  5. Set Minimum TLS Version: TLS 1.2

4.5 Update OAuth Redirect URIs

Update OAuth providers with your custom domain: Google OAuth:
  • Add redirect URI: https://dashtray.com/api/auth/callback/google
GitHub OAuth:
  • Update Authorization callback URL: https://dashtray.com/api/auth/callback/github

4.6 Update Convex SITE_URL

npx convex env set SITE_URL https://dashtray.com --prod

4.7 Update DodoPayments Webhook

  1. In DodoPayments dashboard, go to Webhooks
  2. Update webhook URL to use custom domain (if desired):
    • Keep: https://your-deployment.convex.site/api/webhooks/dodo (recommended)
    • Or use: https://dashtray.com/api/webhooks/dodo

Step 5: Configure Security Headers

5.1 Add _headers File

Create static/_headers:
/*
  X-Frame-Options: DENY
  X-Content-Type-Options: nosniff
  X-XSS-Protection: 1; mode=block
  Referrer-Policy: strict-origin-when-cross-origin
  Permissions-Policy: camera=(), microphone=(), geolocation=()
  Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self' https://*.convex.cloud https://*.convex.site; frame-ancestors 'none';

5.2 Configure CORS

In src/convex/http.ts, ensure CORS is configured:
export default httpRouter();

// Add CORS headers
httpRouter.use((req, res, next) => {
  res.setHeader('Access-Control-Allow-Origin', process.env.SITE_URL!);
  res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
  res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
  next();
});

Step 6: Verification Checklist

6.1 Test Authentication

  • Sign up with email works
  • Email verification received
  • Login works
  • Password reset works
  • Google OAuth works (if configured)
  • GitHub OAuth works (if configured)

6.2 Test Core Features

  • Create project works
  • Connect integration (Stripe) works
  • Metrics sync works
  • Dashboard displays correctly
  • Widgets render correctly
  • Alerts work (Pro+ only)
  • AI chat works (with API key)

6.3 Test Billing

  • Upgrade to Pro works
  • DodoPayments checkout loads
  • Test payment succeeds
  • Webhook received
  • Subscription status updated
  • Features unlocked

6.4 Test Performance

  • Homepage loads < 2s
  • Dashboard loads < 3s
  • API responses < 500ms
  • No console errors
  • Mobile responsive

6.5 Test Security

  • HTTPS works
  • HTTP redirects to HTTPS
  • Security headers present
  • No sensitive data in logs
  • API keys encrypted
  • Rate limiting works

Step 7: Monitoring Setup

7.1 Convex Monitoring

  1. Go to Convex Dashboard
  2. Select your production deployment
  3. Set up alerts:
    • Error rate > 1%
    • Function duration > 5s
    • Database query time > 1s

7.2 Cloudflare Analytics

  1. In Cloudflare Pages, go to Analytics
  2. Monitor:
    • Page views
    • Unique visitors
    • Bandwidth
    • Error rates

7.3 Uptime Monitoring

Set up external monitoring: UptimeRobot (Free):
  1. Sign up at uptimerobot.com
  2. Add monitor:
    • Type: HTTPS
    • URL: https://dashtray.com
    • Interval: 5 minutes
  3. Add alert contacts (email, Slack, etc.)

7.4 Error Tracking (Optional)

Sentry:
  1. Sign up at sentry.io
  2. Create new project
  3. Install SDK:
    pnpm add @sentry/sveltekit
    
  4. Configure in src/hooks.client.ts

Step 8: Backup Configuration

8.1 Export Convex Environment Variables

# Export to file
npx convex env list --prod > convex-env-production.txt

# Encrypt the file
gpg -c convex-env-production.txt

# Store encrypted file securely
# Delete plaintext file
rm convex-env-production.txt

8.2 Document Configuration

Create a secure document with:
  • Convex deployment URL
  • Cloudflare project name
  • DodoPayments product IDs
  • OAuth client IDs
  • Domain registrar details
  • DNS configuration
Store in password manager or encrypted storage.

8.3 Set Up Automated Backups

Convex automatically backs up data, but you can also:
# Export data periodically
npx convex export --path ./backups/$(date +%Y-%m-%d) --prod
Consider setting up a cron job for regular exports.

Troubleshooting

Deployment Fails

Convex deployment fails:
# Check for errors
npx convex logs --prod

# Verify schema
pnpm check
Cloudflare build fails:
  • Check build logs in Cloudflare dashboard
  • Verify environment variables are set
  • Ensure Node.js version is 18

Site Not Loading

  1. Check DNS propagation: whatsmydns.net
  2. Verify SSL certificate is active
  3. Check Cloudflare Pages deployment status
  4. Review browser console for errors

Webhooks Not Working

  1. Verify webhook URL is correct
  2. Check webhook secret matches
  3. Review Convex logs for errors
  4. Test webhook in DodoPayments dashboard

Authentication Issues

  1. Verify BETTER_AUTH_SECRET is set
  2. Check SITE_URL matches actual domain
  3. Verify OAuth redirect URIs are correct
  4. Check Convex logs for auth errors

Next Steps

  • Set up CI/CD (see deployment.md)
  • Configure monitoring alerts
  • Set up status page
  • Create runbook for common issues
  • Schedule regular backups
  • Plan for scaling

Support