Vercel

From G1Joshi/Agent-Skills · View interactive version

Vercel is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert Vercel platform assistance covering Next.js deployment, Edge Middleware, Serverless Functions, Turborepo, and analytics. Use when deploying frontend frameworks and serverless backends globally.

How to use this skill

Skill file

Vercel

Vercel is a frontend cloud platform providing automated CI/CD deployments, edge middleware, global content distribution, and serverless compute tailored for modern web frameworks.

When to Use

Quick Start

npm i -g vercel

# Deploy (Preview)
vercel

# Deploy (Production)
vercel --prod

Core Concepts

Edge Middleware Configuration (middleware.ts)

Executing routing and authentication checks at the network edge:

// middleware.ts
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export function middleware(request: NextRequest) {
  const token = request.cookies.get("auth_token")?.value;

  // Protect dashboard routes
  if (request.nextUrl.pathname.startsWith("/dashboard") && !token) {
    const loginUrl = new URL("/login", request.url);
    loginUrl.searchParams.set("from", request.nextUrl.pathname);
    return NextResponse.redirect(loginUrl);
  }

  // Geolocation header injection
  const response = NextResponse.next();
  const country = request.geo?.country || "US";
  response.headers.set("x-user-country", country);

  return response;
}

export const config = {
  matcher: ["/dashboard/:path*", "/api/secure/:path*"],
};

Declarative Vercel Configuration (vercel.json)

Configuring custom headers, rewrites, and function memory:

{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "cleanUrls": true,
  "trailingSlash": false,
  "headers": [
    {
      "source": "/(.*)",
      "headers": [
        { "key": "X-Content-Type-Options", "value": "nosniff" },
        { "key": "X-Frame-Options", "value": "DENY" }
      ]
    }
  ],
  "functions": {
    "api/export-pdf.ts": {
      "memory": 1024,
      "maxDuration": 30
    }
  }
}

Vercel CLI Deployment Operations

Deploying and pulling remote environments:

# Link local repository to Vercel project
vercel link

# Pull production environment variables to local .env
vercel env pull .env.local

# Deploy preview build to Vercel edge network
vercel

# Deploy to production domain
vercel --prod

Common Patterns

Geolocation Edge Middleware with Custom Rewrites

Problem: Personalizing content by visitor country without server-side rendering latency.

Solution:

Use Vercel Edge Middleware with geolocation:

import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export function middleware(request: NextRequest) {
  const country = request.geo?.country || "US";

  if (country === "GB") {
    return NextResponse.rewrite(new URL("/uk", request.url));
  }
  return NextResponse.next();
}

export const config = {
  matcher: ["/"],
};

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| :------------------------------ | :------------------------------------------------------------------------------------ | :---------------------------------------------------------------------------------------- |

| FUNCTION_INVOCATION_TIMEOUT | Serverless Function execution exceeded plan duration limit (15s hobby, 60s pro). | Optimize slow external queries or split into background task. |

| Build Cache Miss on Turborepo | Environment variables changing between builds without being declared in turbo.json. | Add cache-invalidating env vars to globalEnv in turbo.json. |

| 404 Not Found on static asset | Asset path missing leading slash or output directory misconfigured. | Verify outputDirectory setting matches framework build output (e.g. dist or .next). |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.