Environment Variables
Velocity uses environment variables for configuration that varies between environments.
Create your environment file from the example:
cp .env.example .envVariable Reference
Section titled “Variable Reference”Required
Section titled “Required”# Your production domain (no trailing slash)SITE_URL=https://yoursite.comAnalytics (Optional)
Section titled “Analytics (Optional)”# Google AnalyticsPUBLIC_GA_MEASUREMENT_ID=G-XXXXXXXXXX
# Google Tag ManagerPUBLIC_GTM_ID=GTM-XXXXXXXForm Handling (Optional)
Section titled “Form Handling (Optional)”# Custom form endpointCONTACT_FORM_ENDPOINT=https://api.yoursite.com/contactSearch Verification (Optional)
Section titled “Search Verification (Optional)”# Search engine verification codesGOOGLE_SITE_VERIFICATION=your-google-codeBING_SITE_VERIFICATION=your-bing-codePublic vs Private Variables
Section titled “Public vs Private Variables”Public Variables (Browser-Accessible)
Section titled “Public Variables (Browser-Accessible)”PUBLIC_GA_MEASUREMENT_ID=G-XXXXXXXXXX # ✅ Safe - just a tracking IDPUBLIC_API_URL=https://api.example.com # ✅ Safe - public endpointPrivate Variables (Server-Only)
Section titled “Private Variables (Server-Only)”API_SECRET_KEY=sk_live_xxxxx # ✅ Safe - server onlyDATABASE_URL=postgres://... # ✅ Safe - server onlyPUBLIC_API_KEY=sk_xxxxx # ❌ DANGER - exposed to browser!Accessing Variables
Section titled “Accessing Variables”In Astro Components
Section titled “In Astro Components”---// Server-side (both public and private)const siteUrl = import.meta.env.SITE_URL;const apiKey = import.meta.env.API_SECRET_KEY;---In Client-Side JavaScript
Section titled “In Client-Side JavaScript”// Only PUBLIC_ prefixed variables work hereconst gaId = import.meta.env.PUBLIC_GA_MEASUREMENT_ID;Environment-Specific Files
Section titled “Environment-Specific Files”For different environments, create:
.env— Local development (not committed).env.production— Production overrides.env.example— Template for team members (committed)
Deployment Platforms
Section titled “Deployment Platforms”Vercel
Section titled “Vercel”Set variables in Project Settings → Environment Variables.
Netlify
Section titled “Netlify”Set variables in Site Settings → Build & Deploy → Environment.
Cloudflare Pages
Section titled “Cloudflare Pages”Set variables in Settings → Environment Variables.