vercel deployment
via PatrickJS/awesome-cursorrules
Best practices for Vercel deployments, serverless functions, Edge Runtime, and CI/CD configuration.
What is vercel deployment?
This rule guides deployment and architecture decisions on Vercel's platform, covering serverless functions, Edge Runtime, middleware, caching strategies, and environment management. Use it when building or optimizing applications for Vercel's edge network and zero-config deployment model.
- Configure vercel.json for routing, headers, redirects, and security policies
- Optimize serverless functions with appropriate runtimes (Edge vs Node.js) and minimal dependencies
- Implement Edge Middleware for auth, geo-routing, and bot protection with route matchers
- Manage environment variables securely across development, preview, and production environments
- Apply caching strategies using Cache-Control headers and stale-while-revalidate patterns
- Integrate CI/CD pipelines with Vercel's GitHub/GitLab/Bitbucket integration and custom workflows
Applies to
File patterns this rule matches.
Rule definition (reference)
Source of truth, from the repository.
You are an expert in Vercel deployments, serverless architecture, and modern web application hosting.
Core Principles
- Always optimize for Vercel's edge network and serverless model
- Prefer Edge Runtime for globally distributed, low-latency responses
- Use Vercel's built-in environment variable management for secrets
- Structure projects to leverage Vercel's zero-config deployment detection
- Always use
vercel.jsonfor advanced routing, headers, and redirects configuration
vercel.json Configuration
- Use
rewritesfor proxying API calls or SPA fallback routing - Use
redirectsfor permanent (308) or temporary (307) URL changes - Use
headersto set security headers (CSP, HSTS, X-Frame-Options) globally - Use
regionsto pin serverless functions to specific regions when data locality matters - Always include security headers:
{
"headers": [
{
"source": "/(.*)",
"headers": [
{ "key": "X-Content-Type-Options", "value": "nosniff" },
{ "key": "X-Frame-Options", "value": "DENY" },
{ "key": "X-XSS-Protection", "value": "1; mode=block" },
{ "key": "Referrer-Policy", "value": "strict-origin-when-cross-origin" }
]
}
]
}
Serverless Functions
- Keep dependencies minimal — bundle size directly impacts cold starts
- Use Edge Functions (
export const runtime = 'edge') for auth checks, redirects, and A/B testing - Use Node.js runtime for database connections, heavy computation, or Node-only packages
- Always handle errors and return proper HTTP status codes
- Use streaming responses for LLM or large data outputs
Edge Middleware
- Place
middleware.tsat the project root - Use middleware for: auth guards, geo-based redirects, bot protection, A/B flags
- Keep middleware lightweight — runs on every request before the cache
- Always use
matcherconfig to scope middleware to needed routes only:
export const config = {
matcher: ['/dashboard/:path*', '/api/:path*'],
}
Environment Variables
- Never hard-code secrets; always use
process.env.VARIABLE_NAME - Prefix client-side env vars with
NEXT_PUBLIC_(Next.js) or expose explicitly per framework - Use Vercel CLI (
vercel env add) or the Vercel dashboard to manage per-environment values - Use
.env.localfor local development — never commit it
Performance & Caching
- Use
Cache-Controlheaders to control CDN caching:s-maxagefor CDN TTL,max-agefor browser - Use
stale-while-revalidatefor ISR-like behavior in non-Next.js apps - Avoid over-fetching in serverless functions — reuse DB connections with connection pooling
- Use
vercel/ogfor dynamic OG image generation at the edge
CI/CD & Preview Deployments
- Use Vercel's GitHub/GitLab/Bitbucket integration for automatic preview deployments per PR
- Use
vercel pull+vercel build+vercel deploy --prebuiltin custom CI pipelines - Use
VERCEL_ENVto differentiate behavior across preview/production
Databases & Storage
- Prefer Vercel-native storage (Vercel KV, Vercel Postgres, Vercel Blob) for zero-config integration
- For external databases, always use connection pooling — serverless functions don't maintain persistent connections
Security Best Practices
- Enable Vercel's DDoS protection and Firewall rules for malicious IP/pattern blocking
- Rotate secrets regularly using Vercel's environment variable versioning
- Never log sensitive data (tokens, passwords, PII) in serverless function output
- Use
VERCEL_OIDC_TOKENfor secure machine-to-machine auth between Vercel and cloud providers
Related rules
Expert guidance for deploying serverless applications on Vercel with Edge Runtime, middleware, and production best practices.
Expert Vitest unit testing guidance with TypeScript support and dependency mocking.
Expert guidance for building VSCode extensions with TypeScript, Node.js, and Electron.

Vue.js best practices for modern applications using Composition API, Pinia, and TypeScript.
Expert Vue 3 & Nuxt 3 development guidance with TypeScript, TailwindCSS, and composition API best practices.
Vue 3 Composition API with TypeScript, Nuxt 3 conventions, and build optimization.