Getting the deployment URL programmatically

I’m looking to programmatically get the deployment URL in my backend code in order to send it as a parameter to a third party service. Is there a way I can get this URL into an environment variable automatically during deployment similar to how XDN_ENVIRONMENT_NAME is set? Or is there another option for getting it?

Note: I’m trying to get the URL without access to req or window.

Can you expand on your motivation? Why not just use the host header on the request? You could also add a variable to the environment.

@mark.brocato can you expand on what you mean by the host header on the request, or how you would recommend using an env variable?

This came up today and the use case is that github actions will be doing the deployment, and then we want to take the unique deployment permalink and use it in the same github action to send to a testing tool.

1 Like

@patrick.saweikis
This case with github actions is necessary to allow us to use Calibre

Here is the github deployment statuses API

There isn’t a way to get the URL programmatically at the moment. Testing the permalink also isn’t ideal because it wouldn’t include the edge/caching logic. Could you deploy to an environment, which has a fixed URL, and run your tests against that instead?

Update: Now there is a way to get the deployment URL (and other information about the deployment):
https://docs.layer0.co/guides/cli#section_getting_information_about_the_deployment

1 Like