Netlify DEPLOY_URL and DEPLOY_PRIME_URL are undefined in deploy preview for function #314
Description
Describe the bug
Netlify DEPLOY_URL
and DEPLOY_PRIME_URL
are undefined
in deploy preview.
Not sure if this is the correct repository. If its not please let me know which one is?
Steps to reproduce
- Fork this simple Next.js app (npx create-next-app) https://github.com/watadarkstar/repro-nextjs-netlify-deploy-url
- Deploy to Netlify
- Visit the preview URL /api/hello i.e. https://61ef4b8c60b7120008731b5e--dazzling-ride-812dba.netlify.app/api/hello
Watch the ___netlify-handler function logs and you will see it prints undefined
for both variables yet Netlify is supposed to auto-configure these env variables for you: https://docs.netlify.com/configure-builds/environment-variables/#deploy-urls-and-metadata
In addition to the variables you choose to declare, Netlify has a number of pre-defined variables built in. The following variables are automatically set for your builds, and their values are not changeable.
DEPLOY_URL: URL representing the unique URL for an individual deploy. It starts with a unique ID that identifies the deploy; for example, https://5b243e66dd6a547b4fee73ae--petsof.netlify.app.
DEPLOY_PRIME_URL: URL representing the primary URL for an individual deploy, or a group of them, like branch deploys and Deploy Previews; for example, https://feature-branch--petsof.netlify.app or https://deploy-preview-1--petsof.netlify.app.
Code
https://github.com/watadarkstar/repro-nextjs-netlify-deploy-url/blob/main/pages/api/hello.js
Configuration
Please enter the following command in a terminal and copy/paste its output:
System:
OS: macOS 11.4
CPU: (8) x64 Apple M1
Memory: 142.12 MB / 16.00 GB
Shell: 3.2.2 - /usr/local/bin/fish
Binaries:
Node: 16.11.0 - ~/.nvm/versions/node/v16.11.0/bin/node
Yarn: 1.22.17 - ~/.nvm/versions/node/v16.11.0/bin/yarn
npm: 8.0.0 - ~/.nvm/versions/node/v16.11.0/bin/npm
Watchman: 2022.01.03.00 - /opt/homebrew/bin/watchman```