Back to Nx

Netlify Edge Functions

netlify/edge-functions/README.md

22.7.12.2 KB
Original Source

Netlify Edge Functions

This directory contains edge functions for the nx-dev Next.js application (nx-dev/nx-dev/).

Why are edge functions at the repo root?

Edge functions must be placed here (at the repository root) because of how the nx-dev Netlify site is configured:

  • Base directory: . (repository root)
  • Publish directory: ./nx-dev/nx-dev/.next

Netlify auto-discovers edge functions from netlify/edge-functions/ relative to the base directory. Since the base directory is the repo root, edge functions must be placed here rather than inside nx-dev/nx-dev/.

We attempted to configure a custom path via edge_functions = "nx-dev/nx-dev/netlify/edge-functions" in netlify.toml, but this was not recognized by Netlify's build system.

Edge Functions

rewrite-framer-urls.ts

Proxies all requests to Framer by default and rewrites URLs in the HTML response to use nx.dev instead of the Framer domain. Only paths explicitly kept in Next.js (defined in the nextjsPaths set and excludedPath config) bypass the proxy.

This ensures:

  • Canonical URLs point to nx.dev
  • No duplicate indexing by search engines
  • Consistent branding in meta tags and links

Environment variables (configured in Netlify):

  • NEXT_PUBLIC_FRAMER_URL: The Framer site URL (e.g., https://ready-knowledge-238309.framer.app)

additional-sitemaps.ts

Proxies the per-source sitemaps referenced by the root sitemap index and rewrites URLs to use nx.dev. Separate from the main Framer/blog proxy so that proxy can keep accept: ['text/html'] for compute cost savings.

PathUpstreamEnv var
/sitemap-1.xml<NEXT_PUBLIC_FRAMER_URL>/sitemap.xmlNEXT_PUBLIC_FRAMER_URL
/sitemap-2.xml<BLOG_URL>/blog/sitemap.xmlBLOG_URL

The root sitemap index references these via scripts/patch-sitemap-index.mjs (additionalSitemaps list).

Future

This directory can be removed once the nx-dev Next.js application is retired and all pages are served from the Astro-based documentation site.