后端与数据库

netlify-functions

netlify/context…nd-tools

Write, configure, and deploy Netlify serverless functions in TypeScript, JavaScript, or Go. Use this when adding an API endpoint or backend route, adding a contact form handler, wiring auth or Identity signup/login hooks, identifying which Netlify user is calling a private or team-login-protected app, building streaming or AI-proxy responses, scheduling cron jobs, running long background jobs (batch processing/scraping), reacting to deploy or form events, setting up rate limiting or region/memory config, or reading environment variables and secrets inside a function. Covers file locations, the Request/Context/Response handler shape, path routing, config options, and local testing with netlify dev.

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

安装命令

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

SKILL.md

Netlify Functions

Reach for the modern default-handler API (.mts TypeScript). Export a default async handler taking a web Request and a Netlify Context, returning a web Response. Avoid the legacy AWS Lambda handler shape unless writing Go or migrating old code (see Legacy at the end).

File locations

  • Default directory: netlify/functions/ (relative to base directory). Keep it outside your publish directory or source files ship as static assets.
  • A function is one file or a subdirectory whose entry file is named index or matches the subdirectory name. All of these create a function hello:
    • netlify/functions/hello.mts
    • netlify/functions/hello/hello.mts
    • netlify/functions/hello/index.mts
  • Use .mts (TS) / .mjs (JS) for ES modules. .cts/.cjs force CommonJS; .ts/.js follow the nearest package.json "type".

⚠️ Same-name JS and TS files: the JS one wins. If the functions directory has e.g. items.js and items.ts, the JavaScript function is deployed and the TypeScript file is silently ignored — edits to the .ts have no effect. Keep one file per function name; delete or rename the stale .js when moving a function to TypeScript.

Minimal function

No config export. Serves at /.netlify/functions/hello.