This guide covers deploying the HubSpot Form Builder for production use, including environment configuration, security best practices, and advanced testing setups.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/davidmenlop/HubSpot-Form-builder/llms.txt
Use this file to discover all available pages before exploring further.
Development vs Production
Understand the key differences between development and production environments:| Aspect | Development | Production |
|---|---|---|
| URLs | http://localhost:3001 | https://your-domain.com |
| CORS | Permissive (localhost + Cloudflare) | Restricted to specific domains |
| OAuth Redirect | http://localhost:3001/oauth/... | https://your-domain.com/oauth/... |
| HTTPS | Optional | Required |
| Environment Variables | .env files in repo | Secure environment config |
| Error Logging | Console logs | Production logging service |
| Token Storage | In-memory (session-based) | Persistent database |
Production Environment Setup
Prepare your environment for production deployment.1. Environment Variables
Update your.env files for production:
Backend (server/.env)
Frontend (frontend/.env.production)
.env.production during build.
2. CORS Configuration
Update CORS settings for production domains: Current development config (server/src/index.ts:10-24):Remove the
.trycloudflare.com wildcard in production for security.3. HubSpot OAuth App Configuration
Update your HubSpot OAuth app for production:Create Production App
Create a new OAuth app for production (keep development app separate).Name: “Form Builder (Production)”
Configure Redirect URI
Set the redirect URI to:Must match exactly with
HUBSPOT_REDIRECT_URI in your backend .env.Set Scopes
Required scopes:
forms- Read HubSpot formscontent- For CMS module deploymentforms-uploaded-files- For file uploads in forms (if needed)
Hosting Options
Choose a hosting platform for your Form Builder:Option 1: Vercel (Recommended)
Pros:- Simple deployment from GitHub
- Automatic HTTPS
- Environment variable management
- Serverless functions for backend
Option 2: AWS (EC2 + S3)
Backend: Deploy to EC2 instance- Use PM2 to keep Node.js running
- Configure NGINX as reverse proxy
- Enable HTTPS with Let’s Encrypt
- Build with
npm run build - Upload
dist/folder to S3 - Configure CloudFront for CDN
Option 3: DigitalOcean App Platform
Pros:- Simple configuration
- Automatic deployments from Git
- Built-in database options (for future token persistence)
Testing on Multiple Devices with Cloudflare Tunnels
For development and QA testing across devices, use Cloudflare Tunnels.Why Use Cloudflare Tunnels?
- Test on mobile: Access your local dev server from your phone
- Test on tablets: Check responsive layouts on iPads
- Share with team: Let colleagues test without deploying
- Free: No cost for temporary tunnels
Setup Cloudflare Tunnels
Install Cloudflared
Tunnel Frontend
Open another new terminal:Output:This is your public URL - accessible from any device.
Important Notes About Tunnels
Switching Between Localhost and Tunnels
To revert to localhost:- Stop Cloudflared processes
- Update
frontend/.env: - Update
server/.env: - Restart dev servers
Security Best Practices
1. Keep Secrets Secure
Use Environment Variables
Use Environment Variables
Never hardcode:
- HubSpot Client ID/Secret
- OAuth tokens
- API keys
- Database credentials
.envfiles (local dev, gitignored)- Hosting platform environment variables (production)
- Secret management services (AWS Secrets Manager, etc.)
Rotate Credentials Regularly
Rotate Credentials Regularly
- Change HubSpot Client Secret every 90 days
- Regenerate OAuth tokens on security incidents
- Use different credentials for dev/staging/production
Restrict CORS Origins
Restrict CORS Origins
Only allow specific domains:Never use
origin: '*' in production.2. Token Storage
Current implementation (server/src/oauth.ts):- Tokens stored in-memory on the server
- Lost on server restart
- Single-user session only
- Store tokens in a database (PostgreSQL, MongoDB, Redis)
- Associate tokens with user sessions
- Implement token refresh logic
- Encrypt tokens at rest
3. HTTPS Configuration
Always use HTTPS in production:- Protects OAuth tokens in transit
- Required by HubSpot for OAuth redirects
- Prevents man-in-the-middle attacks
4. Rate Limiting
Protect your API from abuse:5. Input Validation
Validate all inputs on the backend:Monitoring and Logging
Application Logging
Implement structured logging:Error Tracking
Integrate error tracking service: Sentry:Future: HubSpot CLI Integration
The project roadmap includes direct HubSpot CLI integration for automated deployment.Planned Feature
Instead of manually uploading modules:- Generate the module files
- Authenticate with HubSpot CLI
- Upload to Design Manager automatically
- Watch for changes and auto-deploy
HubSpot CLI Setup (Manual Alternative)
You can already use HubSpot CLI manually:Performance Optimization
Frontend
- Code splitting: Vite handles this automatically
- Lazy load components: Use
React.lazy()for heavy components - Memoization: Use
React.memo()for preview components - Debounce drag events: Already implemented in @dnd-kit
Backend
- Cache HubSpot API responses: Store form schemas in Redis (TTL: 1 hour)
- Connection pooling: If using a database for tokens
- Compression: Enable gzip compression
Deployment Checklist
Before going live:- Environment variables configured for production
- CORS restricted to production domains only
- HTTPS enabled and certificates valid
- HubSpot OAuth app redirect URI updated
- Token storage upgraded to persistent database (recommended)
- Rate limiting enabled
- Error tracking configured (Sentry/LogRocket)
- Application logging implemented
- Security headers added (Helmet.js)
- Dependencies updated to latest versions
- Tested on multiple browsers
- Tested on mobile devices
- Form submission tested end-to-end
- Backup and disaster recovery plan in place
Next Steps
Building Forms
Back to form building basics
Exporting Modules
Review module export process
