Netlify Functions - Env Var to indicate to function that it is in Netlify

On other platforms, like Vercel and Cloudflare Pages, an environment variable is defined so that an application knows which platform it is on. Respectively, these are VERCEL and CF_PAGES.

Netlify defines the NETLIFY environment variable at build time, but this is not available to Netlify Functions executing at run time. This might be useful in scenarios when a function might need to know which platform it is executing in.

There is one other use case for this: Auth.js (on which NextAuth.js is based) configures itself to trust forwarded headers from a reverse proxy by inferring the platform it is running on, based on the environment variables mentioned earlier. On Netlify however, a user will have to explicitly set AUTH_TRUST_HOST to true.

If Netlify can define an env var for functions to indicate that Netlify is indeed hosting them, Auth.js can be patched to automatically trust forwarded headers for Netlify, like equivalent platforms, so that Next.js applications that rely on NextAuth.js would just work.

Netlify has a global variable named Netlify that’s defined. Is should be possible to do something like: if (typeof Netlify !== 'undefined') {}