I have PR environments enabled. When I access
RENDER_EXTERNAL_URL, however, it contains the URL of the “parent” deployment, not the URL of the PR deployment. Is there any way I can get the URL for the PR deployment?
Reference: Environment Variables | Render
I’ve checked this on my own service and the value is that of the Pull request preview that was created - what was the service type you experienced this on?
It is a static site, at the moment it is on the Free Tier. It is a React site (built using NextJS).
I’ll do some additional validations to make sure I’m not completely out to lunch on this - now that you’ve validated that it should work.
Ok, I’ve just tested with a static site to be double sure that displays
process.env.REACT_APP_RENDER_EXTERNAL_URL and has a build command of
REACT_APP_RENDER_EXTERNAL_URL=$RENDER_EXTERNAL_URL yarn build and it shows me what I’d expect. Let me know how you get on.
I believe my problem is a result of a NextJS nuance where environment variables without
NEXT_PUBLIC_ prefix are not exposed to the browser (Basic Features: Environment Variables | Next.js). I have verified that
RENDER_EXTERNAL_HOST are both undefined in my app. I’m on a quest now to try to figure out a NextJS solution to the problem.
@John_B I believe I have found a NextJS solution. In the render Environment Variables page, I set a variable such as
$RENDER_EXTERNAL_URL. Then in my app I am able to reference
NEXT_PUBLIC_URL successfully. Again this is a specific nuance in NextJS for static sites. Thanks for your help!
great, much the same for React, having to prefix with REACT_APP_ for it to be accessible at build time. Glad you got it figured out