Overview
PDF AI is designed to be deployed on Vercel with Edge Functions for optimal performance. The application leverages Vercel’s serverless infrastructure to provide fast, scalable PDF processing and AI-powered chat capabilities.Deploying to Vercel
Connect your repository
- Push your code to GitHub, GitLab, or Bitbucket
- Log in to Vercel
- Click “New Project”
- Import your repository
Vercel will automatically detect that this is a Next.js project and configure the build settings.
Configure environment variables
In the Vercel project settings, add all required environment variables:Database:
DATABASE_URL
OPEN_AI_KEY
PINECONE_API_KEYPINECONE_ENVIRONMENT
NEXT_PUBLIC_S3_ACCESS_KEY_IDNEXT_PUBLIC_S3_SECRET_ACCESS_KEYNEXT_PUBLIC_S3_BUCKET_NAME
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEYCLERK_SECRET_KEY
STRIPE_API_KEY(use live keysk_live_...)STRIPE_WEBHOOK_SECRET
NEXT_BASE_URL(e.g.,https://your-domain.vercel.app)
Make sure to use production API keys and credentials, not test/development keys.
Configure build settings
Vercel should automatically detect these settings, but verify:
- Framework Preset: Next.js
- Build Command:
next build - Output Directory:
.next - Install Command:
npm install - Development Command:
next dev
Deploy
Click “Deploy” to start the build process. Vercel will:
- Install dependencies
- Run the Next.js build
- Deploy to the edge network
- Provide a production URL
Edge Functions
PDF AI uses Vercel Edge Functions for API routes to provide:- Low latency: Edge Functions run closer to your users
- Global distribution: Automatically deployed to Vercel’s global edge network
- Scalability: Automatically scales based on demand
Edge Runtime Compatibility
The following API routes are designed to work with Edge Runtime:/api/chat- AI chat endpoint (src/app/api/chat/route.ts:13)/api/stripe- Stripe checkout (src/app/api/stripe/route.ts:9)/api/webhook- Stripe webhooks (src/app/api/webhook/route.ts:20)
Edge Functions have some limitations compared to Node.js serverless functions. Ensure all dependencies are compatible with the Edge Runtime.
Production Considerations
Memory Configuration
In production, you may need to adjust memory limits for processing large PDFs:package.json
Database Connection Pooling
PDF AI uses Neon’s serverless driver which automatically handles connection pooling. No additional configuration is needed, but ensure your Neon plan supports the expected number of concurrent connections.S3 CORS Configuration
Ensure your S3 bucket has proper CORS configuration for your production domain:Stripe Webhooks
Configure your Stripe webhook endpoint:- Go to Stripe Dashboard → Developers → Webhooks
- Add endpoint:
https://your-domain.vercel.app/api/webhook - Select events to listen for (e.g.,
checkout.session.completed) - Copy the webhook signing secret to
STRIPE_WEBHOOK_SECRET
Clerk Domain Configuration
Update your Clerk application with the production domain:- Go to Clerk Dashboard → Your Application
- Navigate to “Paths”
- Update the Home URL and callback URLs to your production domain
Monitoring and Debugging
Vercel Logs
Access real-time logs from your Vercel dashboard:- Go to your project
- Click on “Deployments”
- Select a deployment
- View logs in the “Functions” tab
Error Tracking
Consider integrating error tracking services:- Sentry: Comprehensive error tracking
- LogRocket: Session replay and error tracking
- Vercel Analytics: Built-in analytics and Web Vitals
Performance Monitoring
Monitor your application performance:- Vercel Analytics: Enable in project settings
- Web Vitals: Track Core Web Vitals metrics
- Custom Logging: Add logging to critical paths
Deployment Checklist
Before deploying to production:- All environment variables configured in Vercel
- Production API keys (not test keys) are being used
- Database migrations have been run
- S3 bucket CORS is configured for production domain
- Stripe webhook endpoint is configured
- Clerk domain settings are updated
- Custom domain DNS is configured (if applicable)
- Error tracking is set up
- Analytics are enabled
Known Issues
Current Status
- Local development: Fully functional
- Vercel deployment: Experiencing issues with Edge Functions
Potential Causes
- Edge Runtime Compatibility: Some dependencies may not be compatible with the Edge Runtime
- Environment Variables: Edge Functions may have different variable scoping
- Memory Limits: Edge Functions have stricter memory constraints
- Cold Starts: First request after deployment may timeout
Workarounds
While the team works on resolving the Edge Function issue, consider:-
Use Node.js Runtime: Modify API routes to use Node.js runtime instead of Edge:
-
Increase Function Duration: In
vercel.json: -
Test Thoroughly: Deploy to a preview environment first:
Contributing to the Fix
If you’d like to help resolve this issue:- Clone the repository
- Test locally to confirm it works
- Deploy to Vercel and document the error
- Submit a pull request with potential fixes
- Share your findings in the project issues
Continuous Deployment
Vercel automatically deploys:- Production: When you push to the main/master branch
- Preview: When you create a pull request
- Development: When you push to development branches
Rollback
If a deployment causes issues:- Go to your project in Vercel
- Navigate to “Deployments”
- Find the last working deployment
- Click the three dots menu
- Select “Promote to Production”
Getting Help
- Vercel Documentation: vercel.com/docs
- Next.js Deployment: nextjs.org/docs/deployment
- Project Repository: github.com/Srijan-D/pdf.ai
- Vercel Support: [email protected]