DeveloperPatient
Environment Setup Guide
This document explains how to configure environment variables for the Kulcare Patient App.
Environment Files
.env
Contains environment-specific configuration. Never commit this file - it's included in .gitignore.
.env.example
Template file showing all available environment variables with descriptions. This file is committed to the repository.
Getting Started
-
Copy the example file:
cp .env.example .env -
Fill in the actual values for your environment:
# Edit .env with your actual values nano .env
Environment Variables
API Configuration
| Variable | Required | Description | Example |
|---|---|---|---|
VITE_SERVER_URL | ✅ | Main server URL | https://api-stg.kulcare.com |
VITE_API_BASE_URL | ✅ | API base URL | https://api-stg.kulcare.com |
VITE_ES_SERVER_URL | ❌ | Elasticsearch server URL | https://search.kulcare.com |
VITE_CLINIC_DOCTORS_INDEX | ❌ | ES doctors index name | clinic_doctors |
VITE_ES_SURGERIES_INDEX | ❌ | ES surgeries index name | surgeries |
Third-party Services
| Variable | Required | Description | Example |
|---|---|---|---|
VITE_OPENTOK_SDK_LINK | ❌ | OpenTok/Vonage Video SDK URL | https://static.opentok.com/... |
VITE_RAZORPAY_KEY | ❌ | Razorpay payment gateway key | rzp_test_... |
VITE_MIXPANEL_TOKEN | ❌ | Mixpanel analytics token | abc123... |
VITE_GA_ID | ❌ | Google Analytics ID | G-XXXXXXXXXX |
VITE_PUSHER_CHANNEL | ❌ | Pusher real-time channel | kulcare-channel |
VITE_SENTRY_DSN | ❌ | Sentry error tracking DSN | https://...@sentry.io/... |
Security & Encryption
| Variable | Required | Description | Example |
|---|---|---|---|
VITE_URL_ENCODE_KEY | ❌ | Hashids encryption key | your-secret-key |
VITE_BASIC_AUTH_USERNAME | ❌ | Basic auth username | kulcare_user |
VITE_BASIC_AUTH_PASSWORD | ❌ | Basic auth password | secure_password |
Environment & Release
| Variable | Required | Description | Example |
|---|---|---|---|
VITE_ENVIRONMENT | ✅ | Environment type | development, staging, production |
VITE_LATEST_RELEASE | ❌ | Version tracking | 1.0.0 |
VITE_DEBUG | ❌ | Enable debug logging | true, false |
Environment-Specific Configuration
Development
VITE_API_BASE_URL=https://api-stg.kulcare.com
VITE_ENVIRONMENT=development
VITE_DEBUG=trueStaging
VITE_API_BASE_URL=https://api-stg.kulcare.com
VITE_ENVIRONMENT=staging
VITE_DEBUG=falseProduction
VITE_API_BASE_URL=https://api.kulcare.com
VITE_ENVIRONMENT=production
VITE_DEBUG=falseAPI Proxy Configuration
In development, the app uses a Vite proxy to avoid CORS issues:
// vite.config.ts
server: {
proxy: {
'/api': {
target: process.env.VITE_API_BASE_URL || 'https://api-stg.kulcare.com',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
secure: true,
},
},
}This means:
- Development: API calls go to
/api/*→ proxied to the actual API server - Production: API calls go directly to
VITE_API_BASE_URL
Type-Safe Environment Access
Use the env utility for type-safe environment variable access:
import { env } from '@/lib/env';
// Type-safe access
const apiUrl = env.API_BASE_URL;
const isDebug = env.DEBUG;
const environment = env.ENVIRONMENT; // 'development' | 'staging' | 'production'Validation
Environment variables are automatically validated on app startup in development mode. Missing required variables will throw an error.
Security Best Practices
- Never commit
.envfiles with real credentials - Use different keys for each environment
- Rotate secrets regularly
- Limit access to production environment variables
- Use secure key management for production (e.g., AWS Secrets Manager)
Troubleshooting
API Connection Issues
- Check the browser console for configuration logs (development mode only)
- Verify the API URL is accessible
- Check if CORS is properly configured on the backend
- Ensure the Vite proxy is working correctly
Missing Environment Variables
If you see errors about missing environment variables:
- Check that
.envfile exists - Verify variable names use the
VITE_prefix - Ensure no spaces around the
=sign in.env - Restart the development server after changing
.env
Environment Not Loading
If environment variables aren't being picked up:
- Restart the development server
- Check the
.envfile is in the correct location (project root) - Verify variable names are exactly as documented
- Check for any syntax errors in the
.envfile