Skip to content

Commit 6f87e49

Browse files
committed
feat: update environment variables and CORS configuration for improved deployment and API access
1 parent 035cd16 commit 6f87e49

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

api/.env.production

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ CLOUDINARY_API_KEY=747368826295982
2525
CLOUDINARY_API_SECRET=HbljlQwEoDR6ndvo98KNQy6Lbyk
2626

2727
# CORS Configuration
28-
CLIENT_ORIGIN=https://your-domain.railway.app
28+
CLIENT_ORIGIN=https://aegis-express.vercel.app

api/app.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,21 @@ app.use(express.json({ limit: "1mb" }));
1717
app.use(express.urlencoded({ extended: true }));
1818
app.use(
1919
cors({
20-
origin: process.env.CLIENT_ORIGIN || "*",
20+
origin: [
21+
process.env.CLIENT_ORIGIN || "http://localhost:5173",
22+
"https://aegis-express.vercel.app",
23+
"http://localhost:3000",
24+
"http://localhost:5173",
25+
],
2126
credentials: true,
27+
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
28+
allowedHeaders: [
29+
"Content-Type",
30+
"Authorization",
31+
"Accept",
32+
"Origin",
33+
"X-Requested-With",
34+
],
2235
})
2336
);
2437

@@ -33,6 +46,9 @@ const publicLimiter = rateLimit({
3346

3447
app.use("/api", publicLimiter);
3548

49+
// Handle preflight requests
50+
app.options("*", cors());
51+
3652
app.use("/api/auth", authRoutes);
3753
app.use("/api/deliveries", deliveryRoutes);
3854
app.use("/api/invoices", invoiceRoutes);

client/.env.production

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Production Environment Variables
22
# Note: For Vercel deployment, set these in Vercel Dashboard
3-
VITE_API_BASE_URL=https://your-api-domain.com/api
3+
VITE_API_BASE_URL=https://aegis-express-api.onrender.com/api
44

55
# Optional: Add other environment-specific variables
66
# VITE_APP_NAME=AegisExpress Logistics

client/src/services/api.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ const tokenManager = {
3434
export const api = axios.create({
3535
baseURL: BASE_URL,
3636
timeout: 60000, // Increased to 60 seconds for delivery creation with PDF/email
37-
headers: { "Content-Type": "application/json" },
37+
headers: {
38+
"Content-Type": "application/json",
39+
Accept: "application/json",
40+
},
41+
withCredentials: true, // Include credentials for CORS
3842
});
3943

4044
// --- Refresh Logic ---

render.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ services:
1515
value: 10000
1616
- key: FRONTEND_URL
1717
sync: false # Add your Vercel URL manually
18+
- key: CLIENT_ORIGIN
19+
value: https://aegis-express.vercel.app
1820
- key: MONGODB_URI
1921
sync: false # Add your MongoDB connection string
2022
- key: JWT_SECRET

0 commit comments

Comments
 (0)