vercel-deployment — правило для Cursor: что делает и как установить
Задаёт стандарты Vercel для Edge Runtime, бессерверных функций и vercel.json. Пригодится при настройке маршрутизации и деплоя.
.cursor/rules/vercel-deployment.mdcЧто делает vercel-deployment
Правило инструктирует ассистента следовать архитектуре Vercel при изменении конфигураций проекта. Оно применяется к файлам vercel.json, .vercelignore, middleware.ts, middleware.js, а также к коду внутри api/**/* и app/api/**/*. Ассистент предлагает переносить лёгкие задачи вроде авторизации в Edge Runtime, оставляя Node.js для вычислений.
В инструкциях собраны типовые блоки для vercel.json, включая обязательные заголовки безопасности CSP и X-Frame-Options. Для маршрутизации описаны правила работы с rewrites и постоянными редиректами с кодом 308. Без пула соединений внешние базы данных быстро исчерпают лимиты, поэтому правило требует подключать connection pooling.
Какие задачи решает
- Настроить заголовки безопасности в
vercel.json - Разделить код между Edge Runtime и средой Node.js
- Ограничить область работы middleware через параметр
matcher - Сконфигурировать кэширование CDN с помощью
s-maxage
Примеры запросов агенту
- Добавь в
vercel.jsonстандартные заголовки безопасности и правило редиректа - Напиши
middleware.tsдля проверки сессии и ограничь его маршрутом/dashboard/:path* - Переведи этот эндпоинт в
app/api/на стриминг ответов с Edge Runtime
Как установить vercel-deployment
Вручную: положить файлы
.cursor/rules/vercel-deployment.mdcВо frontmatter: description, globs, alwaysApply
Вручную: положить файлы
.claude/rules/vercel-deployment.mdПоле paths во frontmatter ограничивает файлы: globs из источника → paths
AGENTS.md
Codex читает AGENTS.md: вставьте текст правила туда
Вручную: положить файлы
.github/instructions/vercel-deployment.instructions.mdПоле applyTo задаёт, к каким файлам применять: globs из источника → applyTo
Вручную: положить файлы
.devin/rules/vercel-deployment.mdВручную: положить файлы
.clinerules/vercel-deployment.mdПо шагам, с командами для каждой платформы: Cursor rules: файлы .mdc, четыре режима и замена .cursorrules
Вопросы о vercel-deployment
Как установить vercel-deployment в Cursor?
Создайте файл .cursor/rules/vercel-deployment.mdc в корне проекта и скопируйте в него содержимое правила.
Для каких файлов срабатывает правило?
Оно проверяет пути vercel.json, .vercelignore, middleware.ts, middleware.js, а также эндпоинты в api/**/* и app/api/**/*.
Когда правило выбирает Edge Runtime вместо Node.js?
Edge Runtime назначается для проверки прав, редиректов и потоковой передачи данных с минимальной задержкой. Среда Node.js остаётся для работы с базами данных и специфичными библиотеками.
Исходный текст
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