eleventy-dev-server
eleventy-dev-server copied to clipboard
Add option to inject chosen URL into env variable
This PR introduces a new option to make the eleventy-dev-server insert an environment variable called ELEVENTY_SERVER_BASEURL
with the full base URL that the site is served on.
The main reason for this option is that eleventy-dev-server chooses a port dynamically and I wanted to use that base URL to generate absolute URLs when developing.
Default value is false.
I had to jump through a few hoops to get the tests working because AVA is concurrent by default and shares environment variables.
I wonder if there is a way to expose this to https://www.11ty.dev/docs/events/#eleventy.after?
Something that I discovered later was that an Eleventy site first builds and then eleventy-dev-server
is started so the first build does not have access to this environment variable.
I wonder if there is a way to expose this to https://www.11ty.dev/docs/events/#eleventy.after?
Definitely. You can read process.env.ELEVENTY_SERVER_BASEURL
and then do with that whatever you need. But the first time eleventy.after
is called the environment variable will not exist because by that eleventy-dev-server
has not started yet (and has not decided on a port).
I think I’m okay with this one and am happy to resolve the conflicts but is this something you still want/need @nielsbom? It sounds like it doesn’t solve your problem, in the end 😅
Is this something you still want/need @nielsbom? It sounds like it doesn’t solve your problem, in the end 😅
You're right, it didn't. Closing the PR.