URL environment variable with dev CLI

Hi! Am I doing something wrong or does the URL env var’s not get passed through to the server running the dev command?

My jekyll serve command assumes the URL is localhost:4000. My site uses the configured site.url throughout quite a few places so the dev live server uses absolute URLs which point to localhost:4000 incorrectly. I would expect the URL, DEPLOY_URL and DEPLOY_PRIME_URL to be set to match running through Netlify in production.

This would require the Netlify live URL to be known before running the command so I suspect this isn’t possible yet?

oh so this is for netlify dev --live? in that case yeah the URL is randomly assigned for now. we are indeed thinking of changing that as this is a common request but no timeline on this yet

Interesting question.

What happens if the URL, DEPLOY_URL and DEPLOY_PRIME_URL don’t exist for you @jordan?

1 Like

@jordan I can see from the netlify-dev-plugin code that the netlify dev command sets URL and DEPLOY_URL env vars to the localhost address, but that this isn’t overridden by the external address when adding the --live flag.

I encourage you to file an issue (or a PR!) to get this added to the netlify-dev-plugin for netlify-cli.

1 Like

Oh awesome, thanks for that. It’s weird I didn’t see the env var being set.

I’m actually okay to leave this as it is for now. I fixed my website so it no longer used absolute URL’s everywhere, especially given accessing environment variables in Jekyll wasn’t something I could find easy solutions for.

1 Like

Ah, nice. It does make environment switching so much easier when you can use relative URLs!