Skip to content

Commit 9ae43ca

Browse files
feat: add environment variable templates and configuration for local and production setups; include redirects for Vercel deployment
1 parent 8afd11a commit 9ae43ca

File tree

6 files changed

+111
-12
lines changed

6 files changed

+111
-12
lines changed

client/.env.example

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Environment Variables Template
2+
# Copy this file to .env.local and fill in your values
3+
4+
# API Configuration
5+
VITE_API_BASE_URL=http://localhost:5000/api
6+
7+
# Optional: Application Configuration
8+
# VITE_APP_NAME=AegisExpress Logistics
9+
# VITE_APP_VERSION=1.0.0
10+
11+
# Optional: External Services (if you use any)
12+
# VITE_GOOGLE_MAPS_API_KEY=your_google_maps_api_key
13+
# VITE_CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name

client/.env.production

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Production Environment Variables
2+
# Note: For Vercel deployment, set these in Vercel Dashboard
3+
VITE_API_BASE_URL=https://your-api-domain.com/api
4+
5+
# Optional: Add other environment-specific variables
6+
# VITE_APP_NAME=AegisExpress Logistics
7+
# VITE_APP_VERSION=1.0.0

client/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ dist
1212
dist-ssr
1313
*.local
1414

15+
# Environment files
16+
.env
17+
.env.local
18+
.env.production.local
19+
.env.development.local
20+
1521
# Editor directories and files
1622
.vscode/*
1723
!.vscode/extensions.json

client/ENV_VARIABLES.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Environment Variables Configuration
2+
3+
## Overview
4+
5+
This React application uses Vite environment variables for configuration. All client-side environment variables must be prefixed with `VITE_` to be accessible in the browser.
6+
7+
## File Structure
8+
9+
- `.env.development` - Development environment variables
10+
- `.env.production` - Production environment variables (template only)
11+
- `.env.example` - Template file for new developers
12+
- `.env.local` - Local overrides (not committed to git)
13+
14+
## Required Variables
15+
16+
### API Configuration
17+
18+
```bash
19+
VITE_API_BASE_URL=http://localhost:5000/api # Development
20+
VITE_API_BASE_URL=https://your-api-domain.com/api # Production
21+
```
22+
23+
## Vercel Deployment Setup
24+
25+
### Method 1: Vercel Dashboard (Recommended)
26+
27+
1. Go to your Vercel project dashboard
28+
2. Navigate to **Settings****Environment Variables**
29+
3. Add the following variables:
30+
- **Name**: `VITE_API_BASE_URL`
31+
- **Value**: `https://your-api-domain.com/api`
32+
- **Environment**: Production (or specify environment)
33+
34+
### Method 2: Vercel CLI
35+
36+
```bash
37+
vercel env add VITE_API_BASE_URL
38+
# Enter the value when prompted
39+
```
40+
41+
### Method 3: vercel.json Configuration
42+
43+
Add to vercel.json:
44+
45+
```json
46+
{
47+
"env": {
48+
"VITE_API_BASE_URL": "https://your-api-domain.com/api"
49+
}
50+
}
51+
```
52+
53+
## Usage in Code
54+
55+
```typescript
56+
// Access environment variables in your React components
57+
const apiBaseUrl = import.meta.env.VITE_API_BASE_URL;
58+
59+
// Check if in production
60+
const isProduction = import.meta.env.PROD;
61+
62+
// Check if in development
63+
const isDevelopment = import.meta.env.DEV;
64+
```
65+
66+
## Security Notes
67+
68+
- ⚠️ **Client-side variables are public** - Never store secrets in VITE\_ variables
69+
- ✅ Use VITE\_ prefix for public configuration only
70+
- ✅ API keys and secrets should be handled by your backend API
71+
- ✅ Always validate environment variables in your code
72+
73+
## Local Development
74+
75+
1. Copy `.env.example` to `.env.local`
76+
2. Update the values for your local setup
77+
3. The app will automatically use these variables
78+
79+
## Troubleshooting
80+
81+
- Variables not loading? Check the `VITE_` prefix
82+
- Build issues? Ensure variables are set in Vercel dashboard
83+
- Local development issues? Check `.env.local` file exists and has correct values

client/public/_redirects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* /index.html 200

client/vercel.json

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
{
2-
"version": 2,
3-
"framework": "vite",
4-
"buildCommand": "npm ci && npm run build",
5-
"outputDirectory": "dist",
6-
"installCommand": "npm ci",
7-
"devCommand": "npm run dev",
8-
"cleanUrls": true,
9-
"trailingSlash": false,
10-
"env": {
11-
"NODE_VERSION": "18"
12-
},
132
"rewrites": [
143
{
15-
"source": "/:path*",
4+
"source": "/(.*)",
165
"destination": "/index.html"
176
}
187
]

0 commit comments

Comments
 (0)