测试与安全

netlify-edge-functions

netlify/context…nd-tools

Write, route, cache, and debug Netlify Edge Functions, the Deno-based TypeScript or JavaScript handlers in netlify/edge-functions that run at the network edge in front of static files and serverless functions. Activate this skill whenever someone wants to add auth middleware or a login gate, redirect or rewrite visitors by country or cookie, localize or personalize a page with geolocation, run A/B testing, transform or inject HTML into a response, stream server-side rendering at the edge, or cache an edge response. Also use it when an edge function silently does nothing, runs in the wrong order, ignores its Cache-Control headers, or cannot read an environment variable.

  • 3174 次安装
  • 47 星标
  • 收录于

安装命令

npx skills add https://github.com/netlify/context-and-tools --skill netlify-edge-functions

SKILL.md

Netlify Edge Functions

Use this form

// netlify/edge-functions/hello.ts
import type { Config, Context } from "@netlify/edge-functions";

export default async (request: Request, context: Context) => {
  return new Response(`Hello from ${context.geo.country?.name ?? "somewhere"}`);
};

export const config: Config = { path: "/hello" };
  • One file = one function: a default-export handler plus a config export with the route. Alternatively, declare the route in netlify.toml.
  • Request and Response are global. Import Context and Config types from @netlify/edge-functions.
  • Read env vars with Netlify.env.get(). process.env works only for Next.js middleware.