allBlogsList

Redirects in Composable Setup Part 2

Introduction

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

Comp6

2.     Add necessary config settings, but this is a personal preference. The IDs can also stay in Code.

Comp7

3.     Read from settings and some hardcoding

Comp8

Comp9

4.     Create IRedirectsRepository and RedirectsRepository

Comp10Comp11

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

Comp12

Comp13

Comp14

Comp15

6.     Create an API Endpoint and call the function

Comp16

7.     Don’t forget to register Repos in RegisterContainer.cs

Comp17

8.     Register your route

Comp18

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.

Comp19

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!

References