Architecture Overview
upLegal uses a split deployment architecture:- Frontend (React + Vite): Deployed to Netlify
- Backend (Express API): Deployed to Render
Frontend Deployment (Netlify)
Netlify Configuration
The frontend is configured vianetlify.toml:
Build Settings
| Setting | Value |
|---|---|
| Build command | npm run build |
| Publish directory | dist |
| Node version | 18.0.0 |
API Redirects
Thenetlify.toml configures API requests to proxy to the backend:
SPA Routing
For client-side routing (React Router):Cache Headers
The configuration disables caching for JavaScript bundles and index.html to ensure users always get the latest version:Deploy to Netlify
Connect your repository
- Go to Netlify
- Click “Add new site” > “Import an existing project”
- Connect your Git provider and select the repository
Configure build settings
Netlify will automatically detect the
netlify.toml configuration.Verify:- Build command:
npm run build - Publish directory:
dist - Node version: 18.0.0
Set environment variables
In Netlify dashboard, go to Site settings > Environment variablesAdd all
VITE_* prefixed variables:Deploy
Click “Deploy site”. Netlify will:
- Clone your repository
- Install dependencies (
npm install) - Run build command (
npm run build) - Publish the
distfolder
Backend Deployment (Render)
Server Configuration
The backend server runs onserver.mjs using Express:
- Entry point:
server.mjs - Port: Configured by Render (via
process.env.PORT) or defaults to 3000 - Start command:
npm run serverornode server.mjs
Deploy to Render
Create a new Web Service
- Go to Render Dashboard
- Click “New +” > “Web Service”
- Connect your Git repository
Configure service settings
| Setting | Value |
|---|---|
| Name | uplegal-service |
| Environment | Node |
| Build Command | npm install |
| Start Command | node server.mjs |
| Instance Type | Free (or paid for production) |
Deploy
Click “Create Web Service”. Render will:
- Clone your repository
- Install dependencies
- Start the server with
node server.mjs - Assign a public URL (e.g.,
https://uplegal-service.onrender.com)
CORS Configuration
The backend server is configured with CORS to allow requests from specific origins:Update the
origin array in server.mjs to include your production frontend URL.Build Modes
Production Build
- Minify code with Terser
- Remove console logs
- Optimize bundle size
- No sourcemaps (unless in dev mode)
Development Build
- Sourcemaps for debugging
- Unminified code
- Development environment variables
Vite Build Configuration
Fromvite.config.ts:
Environment-Specific Configuration
Development
- Frontend:
http://localhost:3001 - Backend:
http://localhost:3000 - Use test MercadoPago credentials
- Enable verbose logging
Production
- Frontend:
https://legalup.cl(Netlify) - Backend:
https://uplegal-service.onrender.com(Render) - Use live MercadoPago credentials
- Production logging and error handling
Webhooks Configuration
MercadoPago Webhooks
Configure the webhook URL in MercadoPago dashboard:Monitoring and Logs
Netlify Logs
- Access via Netlify dashboard > Deploys > Select deploy > Deploy log
- Shows build output and deployment status
Render Logs
- Access via Render dashboard > Select service > Logs
- Real-time server logs including:
- API requests
- Environment variable validation
- Payment processing
- Error traces
Server Health Check
Monitor backend health:Rollback and Version Control
Netlify Rollback
- Go to Deploys in Netlify dashboard
- Find a previous successful deploy
- Click Publish deploy
Render Rollback
- Go to service in Render dashboard
- Click Manual Deploy > Select a previous commit
- Or push a git revert to trigger auto-deploy
Troubleshooting
Build Failures
Issue: Netlify build fails with module errors Solution:- Check Node version matches
netlify.toml(18.0.0) - Verify all dependencies are in
package.json - Clear build cache in Netlify settings
API Connection Issues
Issue: Frontend can’t reach backend API Solution:- Verify
VITE_API_BASE_URLpoints to Render service URL - Check CORS configuration includes frontend URL
- Ensure backend is running (check
/healthendpoint)
Environment Variables Not Loading
Issue: App behaves incorrectly or crashes Solution:- Verify all required variables are set in hosting platform
- Frontend variables must be prefixed with
VITE_ - Redeploy after adding new variables
MercadoPago Webhooks Not Working
Issue: Payments don’t update booking status Solution:- Verify
VITE_MERCADOPAGO_WEBHOOK_URLis set correctly - Check webhook is configured in MercadoPago dashboard
- Test webhook endpoint is publicly accessible
- Review Render logs for webhook errors