Skip to main content
rule

vercel-deployment-cursorrules-prompt-file — Cursor rule for Vercel

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.

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

What vercel-deployment-cursorrules-prompt-file does

The rule gives an agent guidance for deploying projects on Vercel. It covers API route placement, choosing Edge or Node.js runtime, handling secrets, and configuring vercel.json. It also addresses middleware, CDN caching, preview deployments, and production releases.

For local work, it recommends .env.local and says not to commit that file. External databases need connection pooling because serverless functions do not keep persistent connections. Middleware runs on each request before the cache, so keep it lightweight and narrow its scope with matcher.

In Cursor, add the rule at .cursor/rules/vercel-deployment-cursorrules-prompt-file.mdc. It covers many deployment concerns, so review the agent’s proposed settings against your project before running vercel --prod.

What it helps with

  • configure routes, headers, and redirects in vercel.json
  • choose a runtime for a serverless function
  • separate environment values for Development, Preview, and Production
  • limit middleware to selected routes
  • prepare a Vercel CLI preview deployment

Example prompts for the agent

  • Set up this project for Vercel and review its vercel.json configuration.
  • Recommend a location and runtime for this API route.
  • Prepare Vercel CLI commands for a preview deployment, without publishing to production.

How to install vercel-deployment-cursorrules-prompt-file

Manually: put the files in place

.cursor/rules/vercel-deployment-cursorrules-prompt-file.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-cursorrules-prompt-file

How do I install vercel-deployment-cursorrules-prompt-file in Cursor?

Add the rule file to your project at .cursor/rules/vercel-deployment-cursorrules-prompt-file.mdc.

What does vercel-deployment-cursorrules-prompt-file do?

It guides deployment work on Vercel, including serverless functions, environment values, caching, middleware, and CI/CD.

Why should I scope middleware with matcher?

Middleware runs on every request before the cache. The rule recommends using matcher to limit it to the routes that need it.

Source text

vercel-deployment-cursorrules-prompt-file.mdc · CC0-1.0
---
description: "Cursor rules for Vercel deployment including serverless functions, Edge Runtime, middleware, caching, CI/CD, and production-ready configuration."
globs: **/*
alwaysApply: false
---
You are an expert in Vercel deployments, serverless architecture, and modern web application hosting.

# Vercel Deployment Guidelines

## 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

## Project Structure
- Place API routes in `/api` directory for automatic serverless function detection (Pages Router) or `/app/api` for App Router
- Use `public/` for static assets that should be served via Vercel's CDN
- Keep serverless functions small and focused — cold start time matters
- Separate long-running tasks to background jobs or external queues (Vercel has a 10s default timeout on Hobby, 60s on Pro)

## 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's Environment Variable UI or CLI (`vercel env add`) to manage per-environment values (Development, Preview, Production)
- Use `.env.local` for local development; never commit it
- Reference `vercel.json` `env` field only for build-time non-secret values

## 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
- Example security headers block:
  ```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 gracefully and return proper HTTP status codes
- Use streaming responses for LLM or large data outputs

## Edge Middleware
- Place middleware in `middleware.ts` at the project root
- Use middleware for: authentication guards, geo-based redirects, bot protection, and A/B flags
- Keep middleware lightweight — it runs on every request before the cache
- Use `matcher` config to scope middleware only to needed routes
  ```ts
  export const config = {
    matcher: ['/dashboard/:path*', '/api/:path*'],
  }
  ```

## Performance & Caching
- Use `Cache-Control` headers to control Vercel's CDN caching behavior
- Use `stale-while-revalidate` for ISR-like behavior in non-Next.js apps
- Set `s-maxage` for CDN cache TTL and `max-age` for browser cache
- Avoid over-fetching in serverless functions — reuse DB connections with connection pooling (PgBouncer, Prisma Accelerate)
- 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
- Set branch protection rules to require passing preview deployment checks
- Use `VERCEL_ENV` environment variable to differentiate behavior across preview/production

## Domain & DNS
- Use Vercel Domains or point external DNS to Vercel's nameservers for automatic SSL
- Always redirect `www` to apex or vice versa — never serve both
- Use `vercel domains add` CLI command for custom domain management

## Monorepo Support
- Set `rootDirectory` in project settings to point to the correct app within a monorepo
- Use Turborepo with Vercel Remote Cache for fast CI builds (`turbo build --filter=...`)
- Scope environment variables per project even in shared monorepos

## 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 do not maintain persistent connections
- Store large files in Vercel Blob or S3-compatible storage, not in the function bundle

## Logging & Observability
- Use `console.log` / `console.error` — Vercel captures these as function logs
- Integrate with Vercel Log Drains to stream logs to Datadog, Sentry, or other observability tools
- Use Vercel Speed Insights and Web Analytics for real-user performance monitoring
- Set up alerts on error rate spikes via Vercel's integrations marketplace

## Security Best Practices
- Enable Vercel's DDoS protection (included on all plans)
- Use Vercel Firewall rules to block malicious IPs and patterns
- 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

## Deployment Workflow
- Run `vercel --prod` only from protected branches (main/master)
- Use `vercel deploy` (without `--prod`) for staging/preview deployments
- Alias stable preview URLs with `vercel alias` for QA sign-off
- Use deployment protection (password or Vercel Access) on preview deployments for private projects

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

Similar IDE rules

All IDE rules for DevOps and infrastructure →

From the same set210

vue-claude-stack This rule guides code generation for Vue 3 and Nuxt 3, covering Composition API, TypeScript, and Pinia. Use it to give an agent consistent project conventions. ★ 41,024repo stars 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 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 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 typescript A Cursor rule that pins down how the agent writes TypeScript: types, naming, error handling. Useful when several people touch the same codebase. ★ 41,024repo stars typescript-vuejs-cursorrules-prompt-file A Cursor rule that tells the agent how to write TypeScript inside Vue.js projects. Useful when you want edits across components to follow the same conventions. ★ 41,024repo stars typescript-vite-tailwind-cursorrules-prompt-file A Cursor rule that pins down TypeScript code style for Vue projects built with Vite and styled with Tailwind. Useful when you want the agent's output to stay predictable. ★ 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