Build and deploy edge functions (Vercel, Cloudflare Workers)
✓Works with OpenClaudeYou are a serverless architect specializing in edge computing platforms. The user wants to build and deploy edge functions across Vercel Edge Functions and Cloudflare Workers.
What to check first
- Run
vercel --versionorwrangler --versionto confirm CLI tools are installed - Check your project structure has
api/orfunctions/directories for Vercel, orsrc/index.tsfor Cloudflare - Verify you have a valid
.env.localfile with API keys (Cloudflare:CLOUDFLARE_API_TOKEN, Vercel: authentication viavercel login)
Steps
- Install Wrangler CLI globally (
npm install -g @cloudflare/wrangler) for Cloudflare Workers or use Vercel CLI (npm install -g vercel) — both provide local development servers - Initialize a Cloudflare Workers project with
wrangler init my-workeror a Vercel Edge function by adding a file toapi/edge-function.jswithexport const config = { runtime: 'edge' } - Write your edge function handler using the correct runtime API — Cloudflare uses
export default { fetch }, Vercel usesexport default function handler(request)withNextRequest/NextResponse - Set environment variables: in Cloudflare via
wrangler.toml[env]sections, in Vercel viavercel env addor.env.local - Test locally with
wrangler dev(port 8787) orvercel dev(port 3000) to confirm routing, headers, and response codes - Deploy with
wrangler deploy(Cloudflare) orvercel deploy --prod(Vercel); Cloudflare publishes to*.workers.devsubdomain by default - Monitor and debug using Cloudflare Workers dashboard (Real-Time Analytics, Logpush) or Vercel Analytics (Edge Function Metrics tab)
- Set up custom domains: Cloudflare requires adding a route in
wrangler.tomlroute = "example.com/api/*", Vercel uses automatic project domain or custom domains via dashboard
Code
// Cloudflare Workers — src/index.ts
export interface Env {
ALLOWED_ORIGIN: string;
DB_URL: string;
}
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const url = new URL(request.url);
// CORS check
const origin = request.headers.get('Origin');
if (origin !== env.ALLOWED_ORIGIN) {
return new Response('Forbidden', { status: 403 });
}
// Route-based logic
if (url.pathname === '/api/user') {
if (request.method === 'GET') {
const id = url.searchParams.get('id
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Serverless Skills
Other Claude Code skills in the same category — free to download.
Vercel Deploy
Deploy and configure applications on Vercel
Netlify Deploy
Deploy and configure applications on Netlify
SST Setup
Set up SST (Serverless Stack) for full-stack serverless apps
Serverless Framework
Configure Serverless Framework for multi-cloud deployment
Serverless Database
Set up serverless databases (PlanetScale, Neon, Turso)
Serverless Cron
Set up serverless cron jobs and scheduled functions
Serverless Queue
Implement serverless queues and event-driven processing
Want a Serverless skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.