Environment Setup
Configure PULSE environments and settings
Environment Setup
Configure PULSE for different environments: development, staging, production.
Environment Variables
Required Variables
# Cloudflare Resources
ACCOUNT_ID=your_account_id
DATABASE_ID=your_database_id
KV_NAMESPACE_ID=your_kv_namespace_id
# API Configuration
API_SECRET=your_api_secret_key_here
DATADOG_SITE=datadoghq.com # or datadoghq.eu
Optional Variables
# Monitoring
DATADOG_API_KEY=your_datadog_key
ENABLE_DATADOG=true
# Feature Flags
DEBUG_MODE=false
ENABLE_RATE_LIMITING=true
Development Environment (.dev.vars)
Create .dev.vars for local testing:
API_SECRET=dev_secret_12345
DATADOG_SITE=datadoghq.com
Then run:
npm run dev
Staging Environment
Configure staging in wrangler.toml:
[env.staging]
vars = { DATADOG_SITE = "datadoghq.com" }
[[env.staging.d1_databases]]
binding = "DB"
database_id = "YOUR_STAGING_DATABASE_ID"
[[env.staging.kv_namespaces]]
binding = "CACHE"
id = "YOUR_STAGING_KV_ID"
Deploy to staging:
wrangler secret put API_SECRET --env staging
wrangler deploy --env staging
Production Environment
Configure production in wrangler.toml:
[env.production]
routes = [
{ pattern = "api.example.com/*", zone_name = "example.com" }
]
[[env.production.d1_databases]]
binding = "DB"
database_id = "YOUR_PRODUCTION_DATABASE_ID"
[[env.production.kv_namespaces]]
binding = "CACHE"
id = "YOUR_PRODUCTION_KV_ID"
Database Configuration
Local D1
For local development:
wrangler d1 execute pulse_analytics --local --file=migrations/*.sql
Remote D1
For staging/production:
wrangler d1 execute pulse_analytics --remote --file=migrations/*.sql
Rate Limiting Configuration
Configure per-endpoint rate limits:
// In src/index.ts
if (path === '/api/v1/auth') {
const limitResult = await env.RATE_LIMITER.limit({
key: `${clientIp}/auth`
})
// 10 requests per minute limit
}
Datadog Integration
Enable monitoring with Datadog:
# Set API key
wrangler secret put DATADOG_API_KEY --env production
# Update wrangler.toml
[vars]
DATADOG_SITE = "datadoghq.com" # or datadoghq.eu
DATADOG_API_KEY = "${DATADOG_API_KEY}"
Feature Configuration
Control features via environment:
// In src/index.ts
const isDevelopment = env.ENVIRONMENT === 'development'
const enableDebug = isDevelopment && env.DEBUG_MODE === 'true'
if (enableDebug) {
console.log('Debug logging enabled')
}
Secrets Management
Best practices for secrets:
# Store secrets separately from config
wrangler secret put API_SECRET --env production
wrangler secret put DATADOG_API_KEY --env production
# Never commit .dev.vars or secrets to git
echo ".dev.vars" >> .gitignore
Next Steps
- Monitoring — Set up observability
- Deployment — Deploy to production
Last updated: April 3, 2026