Vercel Deployment
Deploy the API and your frontend to Vercel’s global edge network.
Prerequisites
- Vercel account (free)
- GitHub repository with your code
- Bot deployed elsewhere (see Railway or VPS)
- Database configured (Turso recommended for serverless)
Quick Deploy
Option 1: One-Click Deploy
Option 2: CLI Deploy
-
Install Vercel CLI
Terminal window npm install -g vercel -
Login to Vercel
Terminal window vercel login -
Deploy from project root
Terminal window cd discord-forum-apivercel -
Configure environment variables when prompted
Project Configuration
vercel.json
Create vercel.json in the project root:
{ "version": 2, "builds": [ { "src": "packages/api/dist/index.js", "use": "@vercel/node" } ], "routes": [ { "src": "/api/(.*)", "dest": "packages/api/dist/index.js" }, { "src": "/(.*)", "dest": "/public/$1" } ]}Build Configuration
In Vercel dashboard or vercel.json:
| Setting | Value |
|---|---|
| Build Command | pnpm build |
| Output Directory | packages/api/dist |
| Install Command | pnpm install |
| Node Version | 20.x |
Environment Variables
Set these in Vercel dashboard → Project → Settings → Environment Variables:
# Database (Turso recommended for serverless)DATABASE_TYPE=tursoTURSO_DATABASE_URL=libsql://your-db.turso.ioTURSO_AUTH_TOKEN=your-token
# API ConfigurationNODE_ENV=productionCORS_ORIGIN=https://yourdomain.com
# OptionalLOG_LEVEL=infoDatabase: Turso Setup
Turso is ideal for Vercel because it’s edge-compatible:
-
Create Turso database
Terminal window turso db create discord-forum-api -
Get credentials
Terminal window turso db show discord-forum-api --urlturso db tokens create discord-forum-api -
Add to Vercel env vars
TURSO_DATABASE_URL: The URL from step 2TURSO_AUTH_TOKEN: The token from step 2
Deploying
From Git
- Push your code to GitHub
- Go to Vercel Dashboard
- Click “Add New Project”
- Import your repository
- Configure settings (see above)
- Click “Deploy”
From CLI
# Development previewvercel
# Production deploymentvercel --prodDomain Configuration
Custom Domain
- Go to Project → Settings → Domains
- Add your domain (e.g.,
api.yourdomain.com) - Configure DNS as shown
- SSL is automatic
CORS Configuration
Update your API to allow your frontend domain:
const app = new Hono();
app.use('*', cors({ origin: process.env.CORS_ORIGIN || 'https://yourdomain.com', credentials: true,}));Frontend + API
Deploying Both
If you have a frontend (Next.js, Astro, etc.) consuming the API:
your-project/├── packages/│ └── api/ # Deployed as API routes├── apps/│ └── web/ # Deployed as frontend└── vercel.jsonvercel.json for monorepo:
{ "version": 2, "builds": [ { "src": "apps/web/package.json", "use": "@vercel/next" }, { "src": "packages/api/dist/index.js", "use": "@vercel/node" } ], "routes": [ { "src": "/api/(.*)", "dest": "packages/api/dist/index.js" }, { "src": "/(.*)", "dest": "apps/web/$1" } ]}Caching
Vercel’s Edge Network caches responses. Configure cache headers:
app.get('/api/threads', async (c) => { const data = await getThreads();
return c.json(data, 200, { 'Cache-Control': 's-maxage=60, stale-while-revalidate=120', });});Monitoring
Vercel Analytics
Enable in Project → Settings → Analytics.
Function Logs
View logs in Project → Deployments → Select deployment → Functions.
Error Tracking
Add Sentry for better error tracking:
import * as Sentry from '@sentry/node';
Sentry.init({ dsn: process.env.SENTRY_DSN,});
// In error handlerapp.onError((err, c) => { Sentry.captureException(err); return c.json({ error: 'Internal error' }, 500);});Limits
Be aware of Vercel’s limits:
| Limit | Hobby (Free) | Pro |
|---|---|---|
| Serverless function duration | 10s | 60s |
| Serverless function memory | 1024 MB | 3008 MB |
| Bandwidth | 100 GB | 1 TB |
| Deployments | Unlimited | Unlimited |
Troubleshooting
Function Timeout
If requests timeout:
- Check database connection (Turso should be fast)
- Add pagination to large queries
- Consider caching expensive operations
- Upgrade to Pro for longer timeouts
Cold Starts
Serverless functions have cold starts. Mitigate with:
- Keep functions small
- Use edge caching
- Consider Vercel Edge Functions for critical paths
Module Not Found
If modules aren’t found:
- Check
vercel.jsonpaths - Ensure
pnpm buildruns successfully - Verify output directory is correct
CORS Errors
- Verify
CORS_ORIGINenvironment variable - Check your frontend URL matches exactly
- Ensure CORS middleware is applied
Complete Example
vercel.json:
{ "version": 2, "buildCommand": "pnpm build", "installCommand": "pnpm install", "framework": null, "builds": [ { "src": "packages/api/dist/index.js", "use": "@vercel/node" } ], "routes": [ { "src": "/api/(.*)", "dest": "packages/api/dist/index.js" } ], "env": { "NODE_ENV": "production" }}Environment Variables (in Vercel dashboard):
DATABASE_TYPE=tursoTURSO_DATABASE_URL=libsql://discord-forum-api-xxx.turso.ioTURSO_AUTH_TOKEN=eyJ...CORS_ORIGIN=https://yourfrontend.vercel.appNODE_ENV=production