machichdigital
RegelCursor RulesLizenz: CC0 1.0frei kopierbar

Netlify Official

Cursor-Regel mit Netlify-eigenen Konventionen für netlify.toml, Functions und Deployment.

⬇ Als Datei laden

× kopiert× heruntergeladenBewertung:

Cursor-Regel mit Netlify-eigenen Konventionen für netlify.toml, Functions und Deployment.

Original-Beschreibung der Autoren: Cursor rules for Netlify development with official integration.

Die Regel

---
description: "Cursor rules for Netlify development with official integration."
globs: **/*
alwaysApply: false
---
<ProviderContextOverrides>
	// Developers can override the content as needed, but it should all be placed in this section.

</ProviderContextOverrides>

ANY RULES IN THE ProviderContextOverrides SECTION CAN OVERRULE SPECIFIC RULES IN ProviderContext

<ProviderContext version="1.0" provider="netlify">
  ## General

  - the `.netlify` folder is not for user code. It should be added to the .gitignore list
  - avoid adding version numbers to imported code. (for example use `@netlify/functions` and never `@netlify/functions@VERSION`)
  - *NEVER* add CORS headers (such as Access-Control-Allow-Origin) unless user EXPLICITLY asks for them.
  - prefer using `netlify dev` to start dev server unless another dev command is requested by the user

  # Guidelines

  - There are 4 types of compute systems you can write code for:
    - Serverless functions - usually used for transactional server/api requests.
    - Edge functions - usually used for code that must modify requests before hitting the server or modifying responses before returning to users.
    - Background functions - longer running functions for asynchronous work.
    - Scheduled functions - schedule logic to run on a CRON-based interval.
  - Netlify Blobs is a general object storage that can be used to accomplish state storage, data storage, etc.
  - Netlify Image CDN enables on-demand image transformations without affecting build times or optimizing images upon upload. It optimizes images dynamically based on client capabilities and caches transformations for performance improvements. Use this when optimizing images dynamically. Don't use this when you need to modify an image during the development/build process.
  - Environment variables are available for storing secrets, API keys, and other values that you want to control external to the code or are too sensitive to put in the code.

  ## Netlify compute

  - NEVER put any type of serverless or edge function in the public or publish directory
  - DO NOT change the default functions or edge functions directory unless explicitly asked to.
  - ALWAYS verify the correct directory to place functions or edge functions into

  ### Context object for serverless functions and edge functions

  Below are the available fields/functions from the context argument to serverless and edge functions.

{ account: { id: string, // Unique ID of the Netlify team account associated with the site and function. }, cookies: { get: (name: string) => string | undefined, // Reads a cookie from the incoming request. set: (options: { name: string; value: string; path?: string; domain?: string; secure?: boolean; httpOnly?: boolean; expires?: Date }) => void, // Sets a cookie on the outgoing response following the CookieStore.set web standard. delete: (nameOrOptions: string | { name: string; path?: string; domain?: string }) => void, // Deletes a cookie on the outgoing response, following the CookieStore.delete web standard. }, deploy: { context: string, // The deploy context (e.g., production, deploy-preview). id: string, // Unique ID of the deploy the function belongs to. published: boolean, // Indicates whether the function belongs to the currently published deploy. }, geo: { city: string, // City name of the client location. country: { code: string, // ISO 3166 country code. name: string, // Full country name. }, latitude: number, // Latitude coordinate of the client location. longitude: number, // Longitude coordinate of the client location. subdivision: { code: string, // ISO 3166 subdivision code (e.g., state or province). name: string, // Subdivision name. }, timezone: string, // Timezone of the location. postalCode: string, // Postal code of the location in its regional format. ip: string, // Client IP address. }, params: Record<string, string>, // Object containing route parameters from the function path configuration. requestId: string, // Unique Netlify request ID. server: { region: string, // The region code where the deployment is running (e.g., us-east-1). }, site: { id: string, // Unique ID for the Netlify site. name: string, // The site’s Netlify subdomain name. url: string, // The main address of the site, which could be a Netlify subdomain or a custom domain. }, }


### the `Netlify` global object

- the `Netlify` object is available in global scope.
- available on all serverless and edge function types

It has the following fields/functions:

{ context: object | null, // The Netlify-specific context object - same as function’s second arg. Available only within function handlers or child scopes; otherwise, it returns null.

env: {
  delete: (name: string) => void, // Deletes an environment variable within the context of the invocation.
  get: (name: string) => string | undefined, // Retrieves the string value of an environment variable; returns undefined if not defined.
  has: (name: string) => boolean, // Checks if an environment variable exists; returns true if it does, otherwise false.
  set: (name: string, value: string) => void, // Sets an environment variable within the invocation context.
  toObject: () => Record<string, string>, // Returns an object containing all environment variables and their values.
},

};


### Serverless Functions (aka Functions, aka Synchronous functions)
- Serverless functions use Node.js and should attempt to use built-in methods where possible
- When adding new npm modules, ensure "node_modules" is in the .gitignore
- ALWAYS use the latest format of a function structure.
- if using typescript, ensure types are installed from `npm install @netlify/functions`

… (hier gekürzt — Kopieren/Download liefert die vollständige Regel)

So nutzt du sie

Die Regel kopieren (Button oben) oder als Datei herunterladen und im Projekt unter .cursor/rules/ ablegen — Cursor lädt sie beim nächsten Start automatisch. Ältere Cursor-Versionen lesen alternativ eine einzelne .cursorrules-Datei im Projektstamm; dort einfach den Regel-Text ohne den Kopfblock zwischen den ----Zeilen einfügen.

Der Regel-Text ist englisch — Cursor versteht ihn unabhängig von der Sprache, in der Sie mit dem Editor chatten.

Im Detail

Netlify ist eine Hosting- und Deployment-Plattform für statische Sites und JAMstack-Projekte mit eingebauten Funktionen wie Serverless Functions, Redirects und Formularverarbeitung. Als „Official“ gekennzeichnet, legt diese Regel nahe, dass sie sich eng an Netlifys eigenen Konventionen orientiert, etwa an der korrekten netlify.toml-Syntax, Build-Einstellungen und der Nutzung von Netlify Functions statt generischer Serverless-Muster. Nützlich für Teams, die auf Netlify deployen und verhindern wollen, dass der KI-Editor Vercel- oder AWS-spezifische Konfiguration vorschlägt. Ohne konkretes Deployment-Ziel ist die Regel überflüssig.

Praxis-Tipp

Vor dem Prompt kurz erwähnen, ob es um Netlify Functions, Edge Functions oder reine Redirects/Headers geht — die Regel greift dann gezielter.

Lizenz & Quelle

Inhalt ansehen (netlify-official.mdc)
Lade …

Erfahrungen & Kommentare.

Funktioniert der Regel bei Ihnen? Tipps, Stolperfallen, Varianten — teilen Sie es mit der Community.

Lade Kommentare …

Ihre IP-Adresse wird zum Schutz vor Missbrauch gespeichert und nach 14 Tagen automatisch entfernt (Datenschutz).

Passt dazu.