When working with Adobe Experience Manager as a Cloud Service (AEMaaCS), managing multiple development environments often introduces complexities in URL resolution. A common scenario involves setting up distinct publish domains for each environment while using Sling Mappings to shorten page URLs. By default, mappings are stored under the /etc/map.dev runmode, causing internal links to resolve to the same domain across environments. This blog outlines a solution to configure Sling Mappings to ensure each development environment resolves internal links to the correct domain.
The Challenge
In AEMaaCS, Sling Mappings are typically used to simplify and shorten URLs. However, when multiple development environments share the same /etc/map.dev runmode, internal links may incorrectly resolve to a common domain. This behavior can lead to incorrect routing and testing issues, as links intended for one environment might point to another’s domain.
The Solution: Using Cloud Manager Environment Variables
AEMaaCS provides a flexible way to address this issue by leveraging Cloud Manager Environment Variables. These variables can dynamically configure Sling Mappings to point each development environment to its respective publish domain.
Steps to Configure Environment-Specific Sling Mappings
- Set Up a Cloud Manager Environment Variable Define a custom environment variable in Cloud Manager for each development environment. For example:
- ETC_MAPPING_LOCATION for Environment A: /etc/map.dev.envA
- ETC_MAPPING_LOCATION for Environment B: /etc/map.dev.envB
- Configure the JcrResourceResolverFactoryImpl Update the org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl.cfg.json file to use the environment variable:
{
"resource.resolver.map.location":"$[env:ETC_MAPPING_LOCATION]","resource.resolver.mapping": [ "/:/" ]
}
The $[env:ETC_MAPPING_LOCATION] placeholder dynamically resolves to the value of the ETC_MAPPING_LOCATION environment variable for the current Cloud Manager environment.
- Set Up Environment-Specific Mappings Create separate mappings for each environment under the respective paths defined in the environment variable:
- /etc/map.dev.envA for Environment A
- /etc/map.dev.envB for Environment B
These mappings will ensure internal links resolve correctly for each environment’s specific domain.
- Test the Configuration Deploy the configuration to each development environment. Verify that internal links resolve to the appropriate domain based on the environment.
Example Use Case
Let’s say you have two development environments:- Environment A: devA-publish.example.com
- Environment B: devB-publish.example.com
By following the steps above, you can configure /etc/map.dev.envA to map internal links to devA-publish.example.com and /etc/map.dev.envB to map to devB-publish.example.com. This ensures that each environment behaves independently without cross-linking issues
Leave a Reply