How can we access domain name from the AEM cloud and use it inside configuration. | Community
Skip to main content
June 20, 2023
Solved

How can we access domain name from the AEM cloud and use it inside configuration.

  • June 20, 2023
  • 3 replies
  • 1795 views

Hi Experts, 

 

Good Morning,

 

Recently I got to learn about the AEM cloud environment variable, I understood how we can add a custom environment variable to an AEM cloud environment and use it on the OSGI services configuration. But I was wondering if we can somehow use the domain name, set for the AEM cloud instance. I did not find any reference about if there is any existing environment variable available for the domain name.

 

Please guide me if this is possible.

 

Thanks.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by aanchal-sikka

Hello @rp2777007 

 

We get domain name from Request using APIs

 

private String getDomainFromURL() { String url = request.getRequestURL().toString(); String hostComponent = ""; try { URI uri = new URI(url); hostComponent = uri.getHost(); } catch (URISyntaxException e) { logger.debug("Unable to parse request URL"); } }

 

 

For constructing URLs to say send in an email, you can use externalizer like https://medium.com/@toimrank/aem-externalizer-and-multisiteexternalizer-e3afad105b8

 

If the requirement is beyond these suggestions, please do let us know

3 replies

Tanika02
Level 7
June 20, 2023

Hello @rp2777007  - 

 

  • Actually, the domain name for your instance is not directly exposed as an environment variable.
  • But what is the exact requirement here? As in why do you want to set the domain name for an instance via environment variables? 
RP2777007Author
June 20, 2023

hi @tanika02 , 

 

I don't want to set the domain name, but I want to utilise the domain name and serve the endpoint of my API along with the domain. Usually we do it using Externalizer configuration, but in my case, we have two dev instances, and if we set configuration according to the environment and service type, it's taking one's domain to another.

aanchal-sikka
Community Advisor
aanchal-sikkaCommunity AdvisorAccepted solution
Community Advisor
June 20, 2023

Hello @rp2777007 

 

We get domain name from Request using APIs

 

private String getDomainFromURL() { String url = request.getRequestURL().toString(); String hostComponent = ""; try { URI uri = new URI(url); hostComponent = uri.getHost(); } catch (URISyntaxException e) { logger.debug("Unable to parse request URL"); } }

 

 

For constructing URLs to say send in an email, you can use externalizer like https://medium.com/@toimrank/aem-externalizer-and-multisiteexternalizer-e3afad105b8

 

If the requirement is beyond these suggestions, please do let us know

Aanchal Sikka
Rohit_Utreja
Community Advisor
Community Advisor
June 20, 2023

Hi @rp2777007 ,

 

As I understand, you have two dev instances and both should use a different domain for API.

You can create an OSGI config which should read domain from environment variables.

Now, it can be deployed to both AEM dev instances. 

But, you can configure different domains for both AEM instances as environment variable. By this way, you will use same OSGI config but with different domains from environment variables.

 

I hope it helps!