{"id":24995,"plugin_id":"plugin_asdk_app_691f1f8f72408191afdbbdf8242bdf86","kind":"skill","collection_source":null,"comparison_source":null,"observed_at":"2026-09-30T23:18:59.214Z","digest":"14cf7d1dcbc838c18e43eef1df663946664df87364513ef62cba0ed51ff26710","against":5400,"payload":{"name":"netlify-edge-functions","description":"Guide for writing Netlify Edge Functions. Use when building middleware, geolocation-based logic, request/response manipulation, authentication checks, A/B testing, or any low-latency edge compute. Covers Deno runtime, context.next() middleware pattern, geolocation, and when to choose edge vs serverless.","included_files":[{"relative_path":"LICENSE.txt","size_in_bytes":10776},{"relative_path":"agents/openai.yaml","size_in_bytes":352},{"relative_path":"assets/netlify-small.svg","size_in_bytes":1291},{"relative_path":"assets/netlify.png","size_in_bytes":2686}],"skill_md_contents":"---\nname: netlify-edge-functions\ndescription: Guide for writing Netlify Edge Functions. Use when building middleware, geolocation-based logic, request/response manipulation, authentication checks, A/B testing, or any low-latency edge compute. Covers Deno runtime, context.next() middleware pattern, geolocation, and when to choose edge vs serverless.\n---\n\n# Netlify Edge Functions\n\nEdge functions run on Netlify's globally distributed edge network (Deno runtime), providing low-latency responses close to users.\n\n## Syntax\n\n```typescript\nimport type { Config, Context } from \"@netlify/edge-functions\";\n\nexport default async (req: Request, context: Context) => {\n  return new Response(\"Hello from the edge!\");\n};\n\nexport const config: Config = {\n  path: \"/hello\",\n};\n```\n\nPlace files in `netlify/edge-functions/`. Uses `.ts`, `.js`, `.tsx`, or `.jsx` extensions.\n\n## Config Object\n\n```typescript\nexport const config: Config = {\n  path: \"/api/*\",                    // URLPattern path(s)\n  excludedPath: \"/api/public/*\",     // Exclusions\n  method: [\"GET\", \"POST\"],           // HTTP methods\n  onError: \"bypass\",                 // \"fail\" (default), \"bypass\", or \"/error-page\"\n  cache: \"manual\",                   // Enable response caching\n};\n```\n\n## Middleware Pattern\n\nUse `context.next()` to invoke the next handler in the chain and optionally modify the response:\n\n```typescript\nexport default async (req: Request, context: Context) => {\n  // Before: modify request or short-circuit\n  if (!isAuthenticated(req)) {\n    return new Response(\"Unauthorized\", { status: 401 });\n  }\n\n  // Continue to origin/next function\n  const response = await context.next();\n\n  // After: modify response\n  response.headers.set(\"x-custom-header\", \"value\");\n  return response;\n};\n```\n\nReturn `undefined` to pass through without modification:\n\n```typescript\nexport default async (req: Request, context: Context) => {\n  if (!shouldHandle(req)) return; // continues to next handler\n  return new Response(\"Handled\");\n};\n```\n\n## Geolocation and IP\n\n```typescript\nexport default async (req: Request, context: Context) => {\n  const { city, country, subdivision, timezone } = context.geo;\n  const ip = context.ip;\n\n  if (country?.code === \"DE\") {\n    return Response.redirect(new URL(\"/de\", req.url));\n  }\n};\n```\n\nLocal dev with mocked geo: `netlify dev --geo=mock --country=US`\n\n## Environment Variables\n\nUse `Netlify.env` (not `process.env` or `Deno.env`):\n\n```typescript\nconst secret = Netlify.env.get(\"API_SECRET\");\n```\n\n## Module Support\n\n- **Node.js builtins**: `import { randomBytes } from \"node:crypto\";`\n- **npm packages**: Install via npm and import by name\n- **Deno modules**: URL imports (e.g., `import X from \"https://esm.sh/package\"`)\n\nFor URL imports, use an import map:\n\n```json\n// import_map.json\n{ \"imports\": { \"html-rewriter\": \"https://ghuc.cc/worker-tools/html-rewriter/index.ts\" } }\n```\n\n```toml\n# netlify.toml\n[functions]\n  deno_import_map = \"./import_map.json\"\n```\n\n## When to Use Edge vs Serverless\n\n| Use Edge Functions for | Use Serverless Functions for |\n|---|---|\n| Low-latency responses | Long-running operations (up to 15 min) |\n| Request/response manipulation | Complex Node.js dependencies |\n| Geolocation-based logic | Database-heavy operations |\n| Auth checks and redirects | Background/scheduled tasks |\n| A/B testing, personalization | Tasks needing > 512 MB memory |\n\n## Limits\n\n| Resource | Limit |\n|---|---|\n| CPU time | 50 ms per request |\n| Memory | 512 MB per deployed set |\n| Response header timeout | 40 seconds |\n| Code size | 20 MB compressed |\n"},"changes":[{"path":"/included_files","type":"changed","before":[{"relative_path":"assets/netlify-small.svg","size_in_bytes":1291},{"relative_path":"assets/netlify.png","size_in_bytes":2686}],"after":[{"relative_path":"LICENSE.txt","size_in_bytes":10776},{"relative_path":"agents/openai.yaml","size_in_bytes":352},{"relative_path":"assets/netlify-small.svg","size_in_bytes":1291},{"relative_path":"assets/netlify.png","size_in_bytes":2686}]}],"summary":"Fields changed: 1. /included_files.","summary_kind":"deterministic","summary_metadata":{}}