Files
ember-market-frontend/CAPROVER-DEPLOYMENT-FIX.md
NotII 57c2fbdf50 Add CapRover deployment fix and improve env var handling
Added CAPROVER-DEPLOYMENT-FIX.md with instructions for required environment variables to prevent 500 errors. Improved validation and fallback logic for SERVER_API_URL and API_BASE_URL in server-api.ts, route.ts, and next.config.mjs to handle missing or invalid values gracefully and log warnings instead of crashing.
2025-09-01 16:31:12 +01:00

2.2 KiB

CapRover Deployment Fix for 500 Errors

🚨 Issue

The domain privacy changes require specific environment variables to be set in CapRover. Missing these causes 500 errors during deployment.

Required Environment Variables in CapRover

Step 1: Set Environment Variables

In your CapRover app settings, add these environment variables:

# Required for API routing
API_BASE_URL=https://your-backend-domain.com
API_HOSTNAME=your-backend-domain.com
SERVER_API_URL=https://your-backend-domain.com/api

# Client-side API URL (should already be set)
NEXT_PUBLIC_API_URL=/api

Step 2: Example Configuration

Replace your-backend-domain.com with your actual backend domain:

# For production deployment
API_BASE_URL=https://internal-api.inboxi.ng
API_HOSTNAME=internal-api.inboxi.ng
SERVER_API_URL=https://internal-api.inboxi.ng/api
NEXT_PUBLIC_API_URL=/api

Step 3: Alternative - Use Internal Service Names

If using CapRover's internal networking:

# Using CapRover internal service names
API_BASE_URL=http://srv-captain--your-backend-app-name
API_HOSTNAME=srv-captain--your-backend-app-name
SERVER_API_URL=http://srv-captain--your-backend-app-name/api
NEXT_PUBLIC_API_URL=/api

🔧 Troubleshooting

Check Environment Variables

In CapRover app logs, you should see:

Building with environment:
- API_BASE_URL: https://your-domain.com
- API_HOSTNAME: your-domain.com
- SERVER_API_URL: https://your-domain.com/api

Common Issues

  1. Undefined variables: Set all required variables in CapRover
  2. Invalid URLs: Ensure no trailing slashes in API_BASE_URL
  3. HTTPS vs HTTP: Match your backend's protocol

Verification

After deployment, check:

  1. App starts without 500 errors
  2. API requests work correctly
  3. No console warnings about undefined variables

🚀 Deploy Steps

  1. Set environment variables in CapRover
  2. Commit and push changes
  3. Redeploy the app
  4. Check logs for successful startup

📝 Notes

  • The next.config.mjs now has safer fallbacks to prevent 500 errors
  • Missing variables will log warnings but won't crash the app
  • For local development, use the .env file as before