Sitecore Headless Next.js – Forwarding custom query parameters to Layout Service

A few weeks ago the following question came up by Robbert Hock on Sitecore Chat:

Contents Resolver question: with Context.HttpContext.Request.Params["item"] I can read the url of the item. But when for example we have a url like /news?page=1, how would I read the page querystring prop in a contents resolver? Somehow I can’t find it, since the request is like /sitecore/api/layout/render/default

Robbert Hock

This is a fair question, if you would like to process custom parameters in your custom Contents Resolver.

Continue reading “Sitecore Headless Next.js – Forwarding custom query parameters to Layout Service”

Sitecore Headless Next.js – Runtime rewrites

When you create a Sitecore Next.js project you will notice there is a configuration file generated, called next.config.js. This config holds different Sitecore related config entries, but in this post I would like to focus on the async rewrites() method. This is a Next.js feature, to handle rewrites in the app. Rewrites can be useful for several things. By default Sitecore uses rewrites to proxy the media and some Sitecore API requests.

Continue reading “Sitecore Headless Next.js – Runtime rewrites”

Sitecore Headless Next.js – Generic component based external API response processing

Since Sitecore Headless and Composable DXP jumped in to our life, designing and architecting Sitecore solutions are changing. The integration layer is moving to the frontend layer and stays decoupled from Sitecore.

On the current project we are working on, almost all Sitecore components have to call different API routes to enrich the Sitecore component with data coming from these external sources. As it’s a requirement to almost all of our components, it makes sense to design a generic solution for serving the merged data to the frontend. I want to thank Richárd Palkó, we designed and implemented this generic solution together and thank you for guiding me on getting familiar with TypeScript, Next.js and React 🙏.

Continue reading “Sitecore Headless Next.js – Generic component based external API response processing”

Sitecore Headless – Wildcard item with datasource content resolver

On one of my first Sitecore Headless project I got a requirement to implement a dynamic URL resolving to display product data from a different root of the Sitecore tree. If it would have been a traditional Sitecore solution I could implement a custom item resolver but in the headless world we need a different kind of mindset to solve problems like this.

Continue reading “Sitecore Headless – Wildcard item with datasource content resolver”

Update NuGet packages in multiple repositories

On my current project we are struggling of updating multiple repositories after we are pushing a new version of our custom NuGet packages. A solution could be to use floating versions but I wanted more control over the versions, because there could be cases where I need different versions on each solutions. Therefore I went in the direction to update the versions manually on a developer machine. This way, pull requests needs to be opened for each package updates, but this is great because I want all developers aware of the changes.

Continue reading “Update NuGet packages in multiple repositories”

Using translation API with Sitecore ASP .NET Core Rendering Host

Currently there is no client side API implementation done of the Sitecore dictionary translation API in the official Sitecore ASP .NET Core SDK, therefore I decided to implement a PoC. After googling a bit I found, Sitecore already provides an API endpoint to resolve dictionary items and it’s already implemented in the JSS clients. So based on this documentation I found the API endpoint on my local Sitecore CM instance, which is

/sitecore/api/jss/dictionary/<site>/<language>/?sc_apikey=<apikey>

The response of this endpoint is the following:

{
"lang": "en",
"app": "Discovering.Sitecore101",
"phrases": {
"label1": "label 1",
"label2": "label 2"
}
}
Continue reading “Using translation API with Sitecore ASP .NET Core Rendering Host”

Sitecore Publishing Web Hook – Sitecore Rendering Host output caching PoC update

Sitecore 10.1 released a few weeks ago and one of the new features is the Publishing Web Hook. The main reason why this is introduced is to able to easily update JAMstack apps on publish. Official step-by-step guide for Vercel deployment can be found on the official Sitecore JSS documentation site, here.

Continue reading “Sitecore Publishing Web Hook – Sitecore Rendering Host output caching PoC update”

Using Sitecore configuration API from Service Configurator

OR when you are facing with the following exception:

[LockRecursionException: A read lock may not be acquired with the write lock held in this mode.]
System.Threading.ReaderWriterLockSlim.TryEnterReadLockCore(TimeoutTracker timeout) +1347
System.Threading.ReaderWriterLockSlim.TryEnterReadLock(TimeoutTracker timeout) +44
Sitecore.DependencyInjection.ServiceLocator.get_ServiceProvider() +176
Sitecore.Configuration.<>c.<.cctor>b__360_0() +9
System.Lazy`1.CreateValue() +734
System.Lazy`1.LazyInitValue() +189
Sitecore.Configuration.Settings.GetSetting(String name) +48
Continue reading “Using Sitecore configuration API from Service Configurator”