Prerequisites
Before deploying to production, ensure you have:
- Node.js 20.0.0 or higher installed
- MongoDB Atlas account (or another MongoDB hosting service)
- Clerk account configured
- Cloudinary account set up
- Stripe account in live mode
- Inngest account configured
- Gmail account with app password for emails
Build Process
Don Palito Jr uses a monorepo structure with a root-level build script that coordinates building both the backend and admin panel.Build Command
From the root directory:package.json):
Build Process Breakdown
Build Process Breakdown
- Install backend dependencies -
npm install --prefix backend - Install admin dependencies -
npm install --prefix admin - Build admin panel -
npm run build --prefix admin
admin/dist/.Starting the Server
After building, start the production server:PORT environment variable) and serves the built admin panel as static files.
Production Environment Setup
1. Database Configuration
Set up MongoDB Atlas for production:Create MongoDB Atlas Cluster
Go to MongoDB Atlas and create a new cluster.
Configure Network Access
Add your production server’s IP address to the IP whitelist, or allow access from anywhere (0.0.0.0/0) if using dynamic IPs.
backend/src/config/db.js:
2. Clerk Authentication
Configure Clerk for production:Update API Keys
Replace test keys with production keys:
CLERK_PUBLISHABLE_KEY=pk_live_...CLERK_SECRET_KEY=sk_live_...
3. Cloudinary Setup
Configure Cloudinary for production image storage:Cloudinary is used for product images and can handle high traffic in production. Consider enabling auto-format and auto-quality optimizations.
4. Stripe Configuration
The payment webhook uses raw body parsing (required by Stripe):
5. Inngest Background Jobs
Configure Inngest for production:Inngest Functions
Inngest Functions
Two background functions are configured in
backend/src/config/inngest.js:-
User Sync (
clerk.user.created)- Creates user in MongoDB
- Sends welcome email
-
User Deletion (
clerk.user.deleted)- Removes user from MongoDB
6. Email Configuration
Set up Gmail for production emails:CORS and Security
Production CORS Configuration
In production, CORS is restricted to your frontend domain:Security Checklist
- All API keys are production keys (not test keys)
- Environment variables are secured (not in version control)
- CORS is configured for production domain only
- MongoDB network access is restricted
- Clerk webhook secret is configured
- Stripe webhook secret is configured
- HTTPS is enabled on production domain
- Rate limiting is configured (if needed)
- Error messages don’t expose sensitive data
Static File Serving
In production, the backend serves the admin panel as static files:admin/dist/ for all non-API routes.
Hosting Recommendations
Don Palito Jr can be deployed to various platforms:Railway (Recommended)
Configure Build
Railway will automatically detect Node.js. Set:
- Build Command:
npm run build - Start Command:
npm start
Add Environment Variables
Add all required environment variables from the Environment Variables page.
Render
DigitalOcean App Platform
VPS (Ubuntu Server)
For self-hosted deployment:For VPS deployment, also configure:
- Nginx as reverse proxy
- SSL certificate (Let’s Encrypt)
- Firewall (UFW)
- Automatic security updates
Health Check
The application includes a health check endpoint:/) also returns API information:
Post-Deployment Verification
After deployment, verify these components:Webhooks
Test webhooks:
- Create a test user in Clerk → verify webhook triggers
- Make a test payment in Stripe → verify webhook processes
Monitoring and Logs
Server Startup Logs
When the server starts successfully, you should see:Important Log Points
- MongoDB connection:
backend/src/config/db.js:7 - Server startup:
backend/src/server.js:124-136 - Webhook events:
backend/src/server.js:78 - Inngest sync:
backend/src/config/inngest.js:15,42
Recommended Monitoring
- Application monitoring: Use services like Sentry or LogRocket
- Uptime monitoring: UptimeRobot or Pingdom
- Performance: New Relic or Datadog
- Error tracking: Sentry integration
Troubleshooting
MongoDB Connection Failed
MongoDB Connection Failed
Symptoms: Server exits with “MONGODB connection error”Solutions:
- Verify
DB_URLis correct - Check MongoDB Atlas IP whitelist
- Verify database user credentials
- Ensure cluster is active
Clerk Webhooks Not Working
Clerk Webhooks Not Working
Symptoms: Users not syncing to databaseSolutions:
- Verify
CLERK_WEBHOOK_SECRETmatches dashboard - Check webhook endpoint URL is correct
- Ensure Inngest is configured
- Review webhook logs in Clerk dashboard
Stripe Payments Failing
Stripe Payments Failing
Symptoms: Checkout not completingSolutions:
- Verify using live keys (not test keys)
- Check webhook endpoint is configured
- Verify
STRIPE_WEBHOOK_SECRET - Review webhook logs in Stripe dashboard
CORS Errors
CORS Errors
Symptoms: Frontend can’t connect to APISolutions:
- Verify
CLIENT_URLmatches your frontend domain - Ensure
NODE_ENV=production - Check frontend is using correct API URL
- Verify credentials are enabled in fetch requests
Admin Panel 404 Errors
Admin Panel 404 Errors
Symptoms: Admin routes return 404Solutions:
- Ensure
npm run buildcompleted successfully - Verify
admin/dist/directory exists - Check
NODE_ENV=productionis set - Restart the server after building
Next Steps
After successful deployment:- Set up automated backups for MongoDB
- Configure domain and SSL certificate
- Set up monitoring and alerts
- Implement rate limiting if needed
- Review and optimize performance
- Set up CI/CD pipeline for automated deployments