🎉 Environment Setup Complete!
Your dev/production environment separation is now fully configured.
What Was Created
Configuration Files
- ✅
.env.local.example— Template for local development - ✅
.env.development.example— Template for Cloudflare preview/dev branch - ✅
.env.production.example— Template for Cloudflare production - ✅
src/firebase.js— Firebase initialization with auto-detection - ✅
public/_headers— Security headers for PWA - ✅
public/_redirects— SPA routing configuration - ✅
wrangler.toml— Cloudflare Pages configuration
Documentation
- ✅
docs/engineering/ENVIRONMENT_SETUP.md— START HERE (step-by-step guide) - ✅
docs/engineering/DEPLOYMENT.md— Complete deployment reference - ✅ Updated
docs/DOCS_INDEX.mdwith new links
Updated Files
- ✅
.gitignore— Added environment variable protection
🚀 Next Steps (Do This Now!)
1. Follow the Environment Setup Guide
Open and follow: docs/engineering/ENVIRONMENT_SETUP.md
This guide walks you through:
- Creating Firebase projects (dev + prod)
- Setting up local
.env.localfile - Configuring Cloudflare Pages
- Testing your first deployment
Time: ~20 minutes
2. Install Firebase SDK
npm install firebase3. Create Your Local Environment File
cp .env.local.example .env.local
# Then edit .env.local with your Firebase dev configHow It Works
Local Development
npm run dev- Runs on
localhost:5173 - Uses
.env.local(your dev Firebase project) - No deployment, just local testing
Development Environment (Staging)
git push origin dev- Auto-deploys to Cloudflare preview URL
- Uses dev Firebase project
- Accessible to team for testing
Production Environment
git push origin main- Auto-deploys to production URL
- Uses production Firebase project
- Live for users
Environment Separation
| Environment | Git Branch | URL | Firebase Project | Config Source |
|---|---|---|---|---|
| Local | N/A | localhost:5173 | dev | .env.local |
| Dev/Staging | dev | *.pages.dev (preview) | dev | Cloudflare Preview vars |
| Production | main | *.pages.dev (production) | prod | Cloudflare Production vars |
Security Features
✅ Environment variables never committed (.gitignore configured) ✅ Separate Firebase projects (dev data never touches production) ✅ Security headers configured (CSP, X-Frame-Options, etc.) ✅ SPA routing works (no 404s on refresh) ✅ PWA-ready (service worker headers configured)
Quick Reference
Files You'll Edit
.env.local— Your local dev config (create from.env.local.example)- Cloudflare dashboard — Set environment variables for deployments
Files You Won't Touch
.env.*.example— These are templates (committed to git)src/firebase.js— Auto-detects environment (no changes needed)
Important Commands
# Local development
npm run dev
# Build for production
npm run build
# Preview production build locally
npm run preview
# Deploy manually (alternative to git push)
npx wrangler pages deploy distTroubleshooting
"Firebase not initialized" error? → Check you created .env.local from .env.local.example
Build fails on Cloudflare? → Make sure you set all environment variables in Cloudflare dashboard
Wrong Firebase project connecting? → Check environment variables for Production vs Preview in Cloudflare
Need more help? → See docs/engineering/DEPLOYMENT.md (full guide)
📖 Read the Full Guides
- Quick setup (20 min): ENVIRONMENT_SETUP.md
- Full reference: DEPLOYMENT.md
- Firebase details: TECHSTACK.md
Ready to start? → Open docs/engineering/ENVIRONMENT_SETUP.md and follow Step 1! 🚀