This document explains how the local development environment is automatically configured when you clone the repository and run it locally, in GitHub Codespaces, or in any development environment.
When you set up Zava Gift Exchange locally, the system automatically creates and configures everything needed for development:
- ✅ Database connection (
local.settings.json) - ✅ Environment variables
- ✅ Docker containers
- ✅ Development servers
- ✅ Debuggers
Zero manual configuration needed! Just run the app.
When you clone and run the app locally:
# Clone the repo
git clone https://github.com/dsanchezcr/zavaexchangegift.git
cd zavaexchangegift
# Option A: Use root setup script (recommended)
npm run setup
# Option B: Start normally (setup runs automatically)
cd api && npm install
npm run devWhat happens:
setup-local-settings.jsautomatically runs- Copies
local.settings.json.example→local.settings.json - Configures for local Cosmos DB emulator
- Dependencies installed
- Ready to start with
npm run devorF5in VS Code
When you open the repo in Codespaces:
# Codespaces automatically runs the postCreateCommand
# which includes:
npm install && cd api && npm install && cp local.settings.json.example local.settings.jsonWhat happens:
- Dev container starts with all extensions pre-installed
- Dependencies installed automatically
local.settings.jsoncreated from template- Docker containers configured in devcontainer
- Ready to develop immediately!
When deployed to Azure:
# CI/CD workflow runs
npm run build
npm run test:e2e
# Deployment
# Azure Static Web Apps provides app settings automatically
# local.settings.json is NEVER usedWhat happens:
- Local settings file is ignored (
.gitignore) - Azure provides real credentials via app settings
- No risk of accidentally using local emulator in production
- Each environment (PR/QA/Prod) gets its own credentials
api/
├── local.settings.json.example ✅ COMMITTED (template only)
└── local.settings.json ❌ .gitignore (auto-generated)
-
local.settings.json.example- Template that's safe to commit- Shows what configuration is available
- Contains non-sensitive defaults
- Used to generate actual settings
-
local.settings.json- Never committed- Your personal development setup
- Contains secrets/keys for your machine
- Generated automatically for each developer
- Safe to modify for local testing
When the setup script runs, it creates this configuration:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "node",
"COSMOS_ENDPOINT": "https://localhost:8081",
"COSMOS_KEY": "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
"COSMOS_DATABASE_NAME": "zavaexchangegift",
"COSMOS_CONTAINER_NAME": "games",
"APPLICATIONINSIGHTS_CONNECTION_STRING": "",
"ACS_CONNECTION_STRING": "",
"APP_BASE_URL": "http://localhost:5173",
"ENVIRONMENT": "local"
},
"Host": {
"CORS": "*",
"CORSCredentials": false
}
}| Variable | Value | Purpose |
|---|---|---|
COSMOS_ENDPOINT |
https://localhost:8081 |
Local emulator URL |
COSMOS_KEY |
Default key | Emulator uses public, non-secret key |
COSMOS_DATABASE_NAME |
zavaexchangegift |
Database name |
COSMOS_CONTAINER_NAME |
games |
Container name |
APP_BASE_URL |
http://localhost:5173 |
Frontend URL |
ENVIRONMENT |
local |
Development mode |
Security Note: The Cosmos DB emulator key is a public, well-known default. It's only for development and provides no real security. Never put this key anywhere near production!
File: npm run setup
npm run setupDoes:
- Runs
scripts/setup-local-settings.js - Checks if
local.settings.jsonexists - If not, copies from
.examplefile - Installs API dependencies
- Shows status message
File: api/package.json - "preinstall" script
"scripts": {
"setup": "node ../scripts/setup-local-settings.js",
"preinstall": "npm run setup"
}Does:
- Runs before
npm installin theapi/folder - Automatically creates
local.settings.jsonif missing - Runs silently (doesn't interrupt workflow)
File: .devcontainer/devcontainer.json
"postCreateCommand": "npm install && cd api && npm install && cp local.settings.json.example local.settings.json 2>/dev/null || true"Does:
- Runs when Codespaces container is created
- Installs root and API dependencies
- Copies settings template to actual file
- Silent failure if file already exists (
|| true)
git clone https://github.com/dsanchezcr/zavaexchangegift.git
cd zavaexchangegiftResult:
- Repository cloned
local.settings.jsondoes NOT exist yetlocal.settings.json.exampleexists
npm installResult:
- Root
node_modules/installed - Setup script copied to
scripts/
Option A: VS Code F5 (Recommended)
# Press F5 in VS Code
# or Ctrl+Shift+D → click play buttonOption B: Manual Start
npm run setup # Creates local.settings.json
docker-compose up -d # Start containers
npm run dev # Start frontend
cd api && npm install && npm start # Start APIResult:
- Setup script creates
local.settings.json - Docker containers start
- Frontend:
http://localhost:5173 - API:
http://localhost:7071 - Cosmos DB:
https://localhost:8081 - Everything connected and working!
# Make changes to src/ or api/src/
# Changes auto-reload
# Add breakpoints and debugSolution: Run setup manually
npm run setupThen verify file exists:
ls api/local.settings.jsonCauses:
- Docker containers not running
- Cosmos DB emulator not healthy
local.settings.jsonmissing or misconfigured
Solution:
# 1. Check Docker
docker-compose ps
# 2. Start if needed
docker-compose up -d
# 3. Check health
docker-compose logs cosmosdb-emulator
# 4. Recreate settings
npm run setupCause: Browser trust issue with self-signed certificate
Solution (Windows/macOS):
# Import certificate
docker-compose exec cosmosdb-emulator curl -k https://localhost:8081 > /dev/nullOr ignore for local development (browser will warn but work).
Old Setup: If you had an encrypted local.settings.json from an older version:
# Delete the old file
rm api/local.settings.json
# Recreate from template
npm run setuplocal.settings.json → Points to emulator
→ Uses local database
→ Email disabled
→ Useful for testing
.devcontainer → Creates local.settings.json
→ Same as local development
→ All dependencies pre-installed
→ Press F5 to start debugging
CI/CD Pipeline → Ignores local.settings.json
→ Uses Azure app settings
→ Real Cosmos DB endpoint
→ Real email service
→ Cannot access local settings file
local.settings.jsonis in.gitignore- Never pushed to git
- Azure Functions reads from
app settingsin Static Web Apps instead - Each environment completely isolated
When you contribute to this project:
- Clone and setup - Automatic, no special steps
- Make changes - Local settings already configured
- Test locally - Works perfectly with emulator
- Create PR - Your
local.settings.jsonnever leaves your computer - CI/CD tests - Automatic testing in clean environment
Everything is automatically isolated. Your local development setup is personal to you and never interferes with:
- Other developers' setups
- GitHub Actions CI/CD
- Production deployments
If you need to change something for testing:
# Edit your local settings
nano api/local.settings.jsonCommon customizations:
{
"Values": {
"COSMOS_ENDPOINT": "https://localhost:8081", // Change emulator address
"COSMOS_KEY": "YOUR_KEY_HERE", // Use real Azure for testing
"ACS_CONNECTION_STRING": "YOUR_ACS", // Enable email testing
"ENVIRONMENT": "testing" // Change to test mode
}
}Note: Changes are local to your machine. Run git restore api/local.settings.json to revert to default.
| Scenario | Setup Process | Result |
|---|---|---|
| Local Clone | npm install → setup script auto-runs |
✅ Ready to code |
| GitHub Codespaces | Container .postCreateCommand auto-runs |
✅ Ready to code |
| CI/CD Pipeline | Ignores local settings | ✅ Uses Azure credentials |
| Production | Never uses local.settings.json | ✅ Complete isolation |
Everything is automatic, isolated, and safe for open source! 🎉