- Created
.envand.env.examplefiles - Updated
config/db.jsto use environment variables for database credentials - Updated
server.jsto useALLOWED_ORIGINSenvironment variable for CORS - Updated
middleware/authMiddlewareto useJWT_SECRETfrom environment - Updated
controller/userControllerto useJWT_SECRETfrom environment - PORT is now configurable via environment variable
- Created
.envand.env.examplefiles - Updated
src/api/api.jsto useVITE_API_URLenvironment variable
Location: Vitra-Backend/.env
- Replace "YOUR_AIVEN_PASSWORD" with actual database password
- Set NODE_ENV to "production"
- Update ALLOWED_ORIGINS with your production domain(s)
- Generate a strong JWT_SECRET (use: node -e "console.log(require('crypto').randomBytes(32).toString('hex'))")
Location: Vitra-Frontend/.env
- Update VITE_API_URL to your production backend URL (e.g., https://api.yourdomain.com)
- For production build: npm run build
cd Vitra-Backend
npm install
node server.jsExpected: "MySQL connected" and "Models synced with MySQL" messages
cd Vitra-Frontend
npm install
npm run build
# Check that dist/ folder is created- No
.envfile is committed to version control (add to.gitignore) - Database credentials are never hardcoded
- JWT_SECRET is strong and unique
- CORS is restricted to your domain (not all origins)
- All sensitive data in environment variables
# Run from backend directory
node -e "require('./config/db').authenticate().then(() => console.log('✅ DB Connected')).catch(err => console.log('❌ DB Error:', err.message))"Test these endpoints before deploying:
- POST
/api/users/register- User registration - POST
/api/users/login- User login - GET
/api/users/me- Get profile (with token) - GET
/api/users/doctors- Get doctors list (with token) - POST
/api/appointments- Create appointment (with token)
DB_NAME=defaultdb
DB_USER=avnadmin
DB_PASSWORD=<your_actual_password>
DB_HOST=mysql-1663326c-kritiyadavcoding-6ab9.a.aivencloud.com
DB_PORT=13918
PORT=5000
NODE_ENV=production
ALLOWED_ORIGINS=https://yourdomain.com,https://www.yourdomain.com
JWT_SECRET=<strong_random_secret>
VITE_API_URL=https://api.yourdomain.com
- Set environment variables in platform dashboard
- Connect GitHub repo for auto-deploy
- Build command:
npm run build - Output directory:
dist
- Add environment variables in platform dashboard
- Ensure
package.jsonhas correct start script - Database SSL is already configured
- Create
.dockerignoreto exclude.env(use.env.examplefor reference) - Copy
.envto server separately (never in docker image) - Use docker secrets or environment variables
| Issue | Solution |
|---|---|
| CORS errors | Check ALLOWED_ORIGINS in backend .env matches frontend domain |
| Database connection fails | Verify DB_NAME, DB_PASSWORD, DB_HOST, and DB_PORT in Render env vars |
| JWT token errors | Ensure JWT_SECRET is consistent and present in .env |
| 404 API errors | Check VITE_API_URL in frontend .env |
| Build fails | Run npm install again, check for syntax errors |
Add this to your .gitignore file to prevent exposing secrets:
.env
.env.local
.env.*.local
node_modules/
dist/
.DS_Store
- Backend starts without errors
- Database connection successful
- User can register with new account
- User can login and receive JWT token
- Protected routes reject requests without token
- Frontend build completes successfully
- Frontend API calls reach backend correctly
- Appointment creation works end-to-end
Status: Ready for staging/production deployment