Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netlify DEPLOY_URL and DEPLOY_PRIME_URL are undefined in deploy preview for function #314

Open
watadarkstar opened this issue Jan 25, 2022 · 0 comments
Labels
type: bug code to address defects in shipped code

Comments

@watadarkstar
Copy link

watadarkstar commented Jan 25, 2022

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

  1. Fork this simple Next.js app (npx create-next-app) https://github.com/watadarkstar/repro-nextjs-netlify-deploy-url
  2. Deploy to Netlify
  3. 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```

@watadarkstar watadarkstar added the type: bug code to address defects in shipped code label Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

1 participant