Overview
The Medical Center API is configured for easy deployment to Vercel and other Node.js hosting platforms. This guide covers deployment best practices, environment configuration, and production considerations.Deployment to Vercel
The API includes avercel.json configuration file for seamless Vercel deployment.
Vercel Configuration
Location:vercel.json
- Uses
@vercel/nodebuilder for the Express server - Routes all requests to
src/server.js - Supports serverless function deployment
Configure environment variables
Set up production environment variables in Vercel:Or configure them in the Vercel dashboard:
- Go to your project settings
- Navigate to Environment Variables
- Add each variable with production values
Deploy to Vercel
Deploy your application:Or push to your connected Git repository for automatic deployments.
Production Environment Variables
Configure these environment variables in your deployment platform:Required Variables
Database Connection Pooling
For production deployments, use connection pooling to handle multiple concurrent requests efficiently.Using PgBouncer
The API is configured to work with PgBouncer for connection pooling:Benefits of Connection Pooling
- Reduced database connections - Reuses connections instead of creating new ones
- Better performance - Handles concurrent requests efficiently
- Scalability - Supports more simultaneous users
- Resource optimization - Prevents connection exhaustion
Important Notes
Alternative Deployment Platforms
Railway
Render
DigitalOcean App Platform
Configure app
- Type: Web Service
- Run Command:
npm start - Build Command:
npm install && npx prisma generate
Pre-Deployment Checklist
Before deploying to production:- All environment variables configured
- Database migrations tested in staging
- Supabase production project created
- Connection pooling enabled (PgBouncer)
- CORS settings configured for production domain
- SSL/TLS enabled for database connections
- Error logging and monitoring set up
- Backup strategy implemented
- API rate limiting configured (if needed)
Post-Deployment Tasks
Database Migration Strategy
For Production Deployments
- Always test migrations in staging first
- Backup the database before migrating:
- Use the direct connection for migrations:
- Verify the migration succeeded:
Rolling Back Migrations
If a migration fails, restore from backup:Monitoring and Logging
Vercel Logs
View real-time logs:Error Tracking
Consider integrating error tracking services:- Sentry - Application error monitoring
- LogRocket - Session replay and logging
- Datadog - Full-stack monitoring
Health Checks
Implement a health check endpoint to monitor API status:Performance Optimization
Connection Pooling
Already configured via PgBouncer inDATABASE_URL
Prisma Connection Pool
Configure Prisma’s built-in connection pool:Caching Strategy
Consider implementing caching for frequently accessed data:- Redis for session management
- In-memory caching for static data (especialidades)
- CDN caching for static assets
Security Best Practices
- Use HTTPS - Always use SSL/TLS in production
- Secure environment variables - Never commit secrets to git
- Enable CORS properly - Configure allowed origins
- Rate limiting - Protect against abuse
- Database security - Use strong passwords and SSL connections
- Keep dependencies updated - Run
npm auditregularly - Rotate credentials - Change keys and passwords periodically
Troubleshooting
Deployment fails
- Check build logs for errors
- Verify all dependencies are in
package.json - Ensure Node.js version compatibility
Database connection errors
- Verify
DATABASE_URLis correct - Check if database allows external connections
- Confirm connection pooling settings
- Test with direct connection first
API returns 500 errors
- Check application logs
- Verify environment variables are set
- Ensure migrations have been applied
- Check Supabase configuration
Performance issues
- Enable connection pooling
- Optimize database queries
- Add appropriate indexes
- Monitor database connection count