Netlify

From G1Joshi/Agent-Skills · View interactive version

Netlify is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert Netlify assistance covering continuous deployments, Netlify Functions, edge redirects (_redirects), and form handling. Use when deploying frontend Jamstack applications and edge web services.

How to use this skill

Skill file

Netlify

Netlify is an essential platform for modern web architectures, providing automated git-based deployments, edge compute, serverless functions, and unified frontend caching primitives.

When to Use

Quick Start

npm i -g netlify-cli

# Run local dev environment (simulates Lambda/Edge)
netlify dev

# Deploy
netlify deploy --prod

Core Concepts

Declarative Configuration with netlify.toml

Defining build commands, headers, and SPA redirects:

# netlify.toml
[build]
  command = "npm run build"
  publish = "dist"

[build.environment]
  NODE_VERSION = "22"

# Security headers across all pages
[[headers]]
  for = "/*"
  [headers.values]
    X-Frame-Options = "DENY"
    X-Content-Type-Options = "nosniff"
    Strict-Transport-Security = "max-age=63072000; includeSubDomains; preload"
    Referrer-Policy = "strict-origin-when-cross-origin"

# Single Page App redirect: forward all unhandled paths to index.html
[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

# Proxy internal API to external microservice backend
[[redirects]]
  from = "/api/*"
  to = "https://api.backend-internal.com/:splat"
  status = 200
  force = true

Netlify Edge Functions (Deno Runtime)

Running geolocation-based transforms directly at the edge:

// netlify/edge-functions/geo-routing.ts
import type { Context } from "@netlify/edge-functions";

export default async (request: Request, context: Context) => {
  const country = context.geo?.country?.code || "US";

  // Redirect visitors from specific regions
  if (country === "FR") {
    return new Response(null, {
      status: 302,
      headers: { Location: "/fr" },
    });
  }

  // Pass request through to original destination with custom headers
  const response = await context.next();
  response.headers.set("x-visitor-country", country);
  return response;
};

export const config = {
  path: "/*",
};

Automated Netlify Forms

Collecting form submissions without writing backend endpoints:

<!-- Native Netlify form capture -->
<form
  name="contact-us"
  method="POST"
  data-netlify="true"
  netlify-honeypot="bot-field"
>
  <input type="hidden" name="form-name" value="contact-us" />
  <p class="hidden"><input name="bot-field" /></p>

  <label>Email: <input type="email" name="email" required /></label>
  <label>Message: <textarea name="message" required></textarea></label>
  <button type="submit">Send Message</button>
</form>

Common Patterns

Declarative netlify.toml with SPA Fallback and Security Headers

Problem: SPA routes returning 404 on browser refresh, combined with missing security response headers.

Solution:

Define routing and headers in netlify.toml:

[build]
  command = "npm run build"
  publish = "dist"

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

[[headers]]
  for = "/*"
  [headers.values]
    X-Frame-Options = "DENY"
    X-Content-Type-Options = "nosniff"
    Referrer-Policy = "strict-origin-when-cross-origin"

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| :-------------------------------------------- | :-------------------------------------------------------------- | :--------------------------------------------------------------------- |

| Page Not Found (404) on route refresh | Missing SPA catch-all redirect rule to /index.html. | Add /* /index.html 200 to _redirects or netlify.toml. |

| Build failed: command not found: ... | Tool or framework dependency not declared in package.json. | Ensure dependencies are in dependencies or devDependencies. |

| Function invocation timed out (default 10s) | Netlify serverless function taking longer than execution limit. | Optimize database calls or request timeout extension in site settings. |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.