The "Failed to load tasks" error occurs because your frontend is trying to connect to localhost:5001 but when deployed, it needs to connect to your actual backend server URL.
First, deploy your backend to a hosting platform:
- Create a new Vercel project
- Upload the
backendfolder - Set environment variables in Vercel dashboard:
PORT=5001 DB_HOST=sql12.freesqldatabase.com DB_USER=sql12791893 DB_PASSWORD=3ALYm8PAgb DB_NAME=sql12791893 - Deploy and get your backend URL (e.g.,
https://your-backend.vercel.app)
- Create a new Web Service
- Upload the
backendfolder - Get your backend URL (e.g.,
https://your-backend.onrender.com)
Once you have your backend URL, update the configuration:
// In config.js, update the production URL:
production: {
API_URL: 'https://your-actual-backend-url.com/api'
}In your hosting platform (Vercel/Netlify), set:
VITE_API_URL=https://your-actual-backend-url.com/api
{
"env": {
"VITE_API_URL": "https://your-actual-backend-url.com/api"
}
}-
Test Backend Health:
curl https://your-backend-url.com/api/health
-
Test Database Connection:
curl https://your-backend-url.com/api/tasks
- Backend deployed to hosting platform
- Environment variables configured
- Database connection working
- Health endpoint responding
- API endpoints accessible
- Backend URL updated in config.js
- Environment variable set in hosting platform
- Frontend deployed with correct configuration
- CORS properly configured on backend
- Backend health check passes
- Database queries work
- Frontend can fetch data
- No CORS errors in browser console
-
Check Browser Console:
- Look for CORS errors
- Check network requests
- Verify API URL being used
-
Test Backend Directly:
curl -X GET https://your-backend-url.com/api/tasks
-
Check Environment Variables:
- Verify VITE_API_URL is set correctly
- Check if config.js is using the right URL
# Set environment variable
vercel env add VITE_API_URL https://your-backend-url.com/api
# Redeploy
vercel --prod# Add to netlify.toml
[context.production.environment]
VITE_API_URL = "https://your-backend-url.com/api"If you're still having issues:
- Share your backend URL
- Check browser console for errors
- Verify database credentials are correct
- Ensure backend is actually running and accessible