Skip to main content
rule

vercel-deployment — Cursor rule: what it does, how to install

Enforces Vercel standards for Edge Runtime, serverless functions, and vercel.json. Useful when configuring routing and deployment pipelines.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/vercel-deployment.mdc
Open on GitHub

What vercel-deployment does

The rule guides the assistant through Vercel serverless conventions during file editing. It targets vercel.json, .vercelignore, root middleware.ts or middleware.js, and endpoints under api/**/* or app/api/**/*. Lightweight auth checks go to Edge Functions, while Node.js runtime remains reserved for heavier compute.

Inside are snippets for vercel.json, covering headers like CSP and X-Frame-Options alongside 308 redirects. Caching instructions rely on s-maxage and stale-while-revalidate directives. Because serverless execution drops persistent connections, external databases strictly require connection pooling.

What it helps with

  • Add security headers and rewrites to vercel.json
  • Scope edge middleware using the matcher config
  • Select between Edge Runtime and Node.js for API handlers
  • Configure CI preview deployments using prebuilt flags

Example prompts for the agent

  • Add standard security headers and an API rewrite to vercel.json
  • Create a middleware.ts auth guard scoped to /dashboard/:path*
  • Update this route in app/api/ to use Edge Runtime with streaming

How to install vercel-deployment

Manually: put the files in place

.cursor/rules/vercel-deployment.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about vercel-deployment

How to install vercel-deployment in Cursor?

Place the rule content into .cursor/rules/vercel-deployment.mdc inside your repository root.

Which files trigger this rule?

It applies to vercel.json, .vercelignore, root middleware files, and any routes within api/**/* or app/api/**/*.

Why does the rule mandate connection pooling?

Serverless functions do not hold persistent connections across invocations. Using connection pooling prevents exhausting database limits.

Source text

vercel-deployment.mdc · CC0-1.0
---
description: "Best practices for Vercel deployments including serverless functions, Edge Runtime, middleware, caching, environment variables, and CI/CD configuration"
globs: ["vercel.json", ".vercelignore", "middleware.ts", "middleware.js", "api/**/*", "app/api/**/*"]
alwaysApply: false
---
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.json` for advanced routing, headers, and redirects configuration

## vercel.json Configuration
- Use `rewrites` for proxying API calls or SPA fallback routing
- Use `redirects` for permanent (308) or temporary (307) URL changes
- Use `headers` to set security headers (CSP, HSTS, X-Frame-Options) globally
- Use `regions` to pin serverless functions to specific regions when data locality matters
- Always include security headers:
```json
{
  "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.ts` at 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 `matcher` config to scope middleware to needed routes only:
```ts
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.local` for local development — never commit it

## Performance & Caching
- Use `Cache-Control` headers to control CDN caching: `s-maxage` for CDN TTL, `max-age` for browser
- Use `stale-while-revalidate` for ISR-like behavior in non-Next.js apps
- Avoid over-fetching in serverless functions — reuse DB connections with connection pooling
- Use `vercel/og` for 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 --prebuilt` in custom CI pipelines
- Use `VERCEL_ENV` to 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_TOKEN` for secure machine-to-machine auth between Vercel and cloud providers

© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules

Similar IDE rules

All IDE rules for DevOps and infrastructure →

From the same set234

The whole set →
vue-3-nuxt-3-typescript-cursorrules-prompt-file A Cursor rule that tells the agent how to write Vue 3 and Nuxt 3 code: Composition API, TypeScript interfaces, Nuxt conventions. Useful when the project already runs this stack. ★ 41,024repo stars vue-3-nuxt-3-development-cursorrules-prompt-file Directs Cursor to follow Vue 3 and Nuxt 3 practices. Requires planning via pseudocode first, uses the Composition API, and relies exclusively on TailwindCSS. ★ 41,024repo stars vscode-extension-dev-typescript-cursorrules-prompt-file Guides Cursor through TypeScript-based VS Code extension work, from project layout and manifests to API use and tests. ★ 41,024repo stars vitest-unit-testing-cursorrules-prompt-file A Cursor rule that turns the agent into a Vitest and TypeScript test writer: it targets business logic and utilities, mocking dependencies with vi.mock. ★ 41,024repo stars vercel-deployment-cursorrules-prompt-file This rule guides an agent through Vercel deployment choices, from environment variables and serverless functions to caching and CI/CD. Use it when preparing a project for deployment. ★ 41,024repo stars unity-cursor-ai-c-cursorrules-prompt-file A Cursor rule that briefs the assistant on a Unity game project in C#: modular code, responsive mechanics, real-time performance. ★ 41,024repo stars uikit-guidelines-cursorrules-prompt-file A rule that enforces programmatic Swift UIKit layouts without Storyboards. It standardizes SnapKit for Auto Layout, isolates data models from UI views, and handles events with closures. ★ 41,024repo stars typo3cms-extension-cursorrules-prompt-file This rule guides Cursor through TYPO3 CMS extension work, from PHP structure to tests and documentation. Use it when an agent is designing a new extension. ★ 41,024repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor