PR Environment Variables (RENDER_EXTERNAL_URL) is not correct

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

Hey Bill,

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?

John B

Hi @John_B,

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.

Bill

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.

John B

Thanks John,

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_URL and 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.

Bill

@John_B I believe I have found a NextJS solution. In the render Environment Variables page, I set a variable such as NEXT_PUBLIC_URL to $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 :slight_smile:

1 Like