Configuration

Configure your Accumo application and set up various features.

Environment Variables

Required Variables

These variables must be set in your .env file:

NEXT_PUBLIC_SITE_URL

Your application's public URL (e.g., https://example.com)

NEXT_PUBLIC_APP_URL

URL for the app section (e.g., https://app.example.com)

NEXT_PUBLIC_API_URL

URL for API endpoints (e.g., https://api.example.com)

Cloudflare Variables

Set these variables in your .dev.vars file for local development:

CF_ACCOUNT_ID

Your Cloudflare account ID

CF_API_TOKEN

API token with necessary permissions

Optional Variables

Additional variables for specific features:

NEXT_PUBLIC_GA_ID

Google Analytics tracking ID

NEXT_PUBLIC_POSTHOG_KEY

PostHog analytics key

Cloudflare Setup

wrangler.toml Configuration

Configure your Cloudflare Workers settings in wrangler.toml:

name = "your-app-name"
main = "src/worker.ts"
compatibility_date = "2024-01-01"

[vars]
ENVIRONMENT = "production"

[[kv_namespaces]]
binding = "KV"
id = "your-kv-namespace-id"

[[d1_databases]]
binding = "DB"
database_name = "your-db-name"
database_id = "your-db-id"

D1 Database

Set up your D1 database:

  1. 1. Create a new D1 database in the Cloudflare dashboard
  2. 2. Copy the database ID to your wrangler.toml
  3. 3. Run migrations: pnpm db:migrate

KV Storage

Set up KV namespaces:

  1. 1. Create a KV namespace in the Cloudflare dashboard
  2. 2. Add the namespace ID to wrangler.toml
  3. 3. Use the KV binding in your code

Authentication

Session Configuration

Configure authentication settings in src/utils/auth.ts:

  • Session duration and expiry
  • Password requirements
  • Rate limiting settings
  • OAuth providers (if used)

Security Best Practices

  • Enable two-factor authentication
  • Set up CORS properly
  • Use secure session cookies
  • Implement proper rate limiting

Deployment

Production Deployment

Deploy your application:

pnpm run deploy

This will build your application and deploy it to Cloudflare Pages.

Environment Management

Set up environment variables in Cloudflare Pages:

  1. 1. Go to your project settings in Cloudflare Pages
  2. 2. Navigate to the Environment Variables section
  3. 3. Add production variables
  4. 4. Configure preview environments if needed

Monitoring

Analytics and Logging

  • Configure Cloudflare Analytics
  • Set up error tracking
  • Monitor Workers performance
  • Track API usage and quotas

Health Checks

Set up monitoring endpoints:

  • API health check endpoint
  • Database connection monitoring
  • KV storage status
  • External service dependencies

Troubleshooting

Database Issues: Check D1 connection and migrations

KV Access: Verify KV namespace bindings

Worker Errors: Check logs in Cloudflare dashboard