Agent Skills
› kinncj/Heimdall
› vercel-patterns
vercel-patterns
GitHub提供 Vercel 部署、Edge/Node 运行时选择、环境变量管理及中间件模式的最佳实践。指导如何配置 vercel.json、安全头设置及本地构建流程,确保高效安全的 Next.js 应用部署。
触发场景
需要部署 Next.js 应用到 Vercel
配置 Vercel 环境变量或中间件
选择 Edge 或 Node.js 运行时
处理 Vercel 路由重写或重定向
安装
npx skills add kinncj/Heimdall --skill vercel-patterns -g -y
SKILL.md
Frontmatter
{
"name": "vercel-patterns",
"description": "Apply Vercel deployment, edge function, and environment variable patterns. Use when deploying to Vercel."
}
SKILL: Vercel Patterns
vercel.json Configuration
{
"framework": "nextjs",
"buildCommand": "npm run build",
"devCommand": "npm run dev",
"installCommand": "npm ci",
"regions": ["iad1"],
"headers": [
{
"source": "/api/(.*)",
"headers": [
{ "key": "X-Content-Type-Options", "value": "nosniff" },
{ "key": "X-Frame-Options", "value": "DENY" },
{ "key": "Strict-Transport-Security", "value": "max-age=31536000" }
]
}
],
"rewrites": [],
"redirects": [
{
"source": "/old-path",
"destination": "/new-path",
"permanent": true
}
]
}
Runtime Selection
// Edge Runtime (low-latency, streaming, middleware)
export const runtime = 'edge';
// Node.js Runtime (heavy compute, native modules, file system)
export const runtime = 'nodejs';
// ISR (static with revalidation)
export const revalidate = 3600; // seconds
Environment Variables
# Pull env vars for local development
vercel env pull .env.local
# Add env var
vercel env add SECRET_KEY production
# List env vars
vercel env ls
Deployment Workflow
# Build locally first (catch errors before deploy)
vercel build
# Deploy prebuilt (faster, recommended for CI)
vercel deploy --prebuilt
# Deploy to production
vercel deploy --prod --prebuilt
Middleware Pattern
// middleware.ts (runs at edge, before every request)
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export function middleware(request: NextRequest) {
// Auth check, rate limiting, A/B testing, etc.
const token = request.cookies.get('token');
if (!token && request.nextUrl.pathname.startsWith('/dashboard')) {
return NextResponse.redirect(new URL('/login', request.url));
}
return NextResponse.next();
}
export const config = {
matcher: ['/dashboard/:path*', '/api/protected/:path*'],
};
Rules
- Run
vercel buildlocally before deploying to catch errors. - Use
vercel env pullto sync environment variables locally. - Prefer Edge runtime for middleware and simple API routes.
- Use Node.js runtime for heavy compute or native module requirements.
- Set security headers for all API routes.
版本历史
- f4ea31f 当前 2026-07-05 10:41


