Redirects in Composable Setup Part 2
If you have not looked at the part 1 of this blog, please do so before continuing. In this blog we will concentrate on the coding and configuring of our back-end Sitecore solution to generate the needed data for the RedirectMappings.json file. This file will then drive the static Redirects generation.
We will start from the step where we left Part 1. So, without further adieu:
Step 4: Create Back-End API Support for generating the RedirectMappingss file
This step would be to code all the necessary endpoints and logic to generate data that feeds into a RedirectMappings.json file.
1. Create Models
2. Add necessary config settings, but this is a personal preference. The IDs can also stay in Code.
3. Read from settings and some hardcoding
4. Create IRedirectsRepository and RedirectsRepository
Note: You will notice that there is a SearchRepository Dependency Injection here. I am using Index to search for items, you can choose to read straight from Sitecore.Context.Database.
5. Below is the logic for redirecting blogs that supports wildcard
6. Create an API Endpoint and call the function
7. Don’t forget to register Repos in RegisterContainer.cs
8. Register your route
Step 5: Execute the PowerShell script file before the build step in the pipeline
Configure your DevOps pipeline to execute the PowerShell script created in step 3 prior to calling the build.
I have scheduled the deployment of Storefront Application (next.js) twice a day on lower environments so that changes from Content Author can be verified as quickly as possible.
And That is it!