How to Resolve a Virtual Directory on a JSS Sitecore Website

restore-sitecore-after-reinstalling-os

This article is about an issue that we faced during building a multisite JSS Sitecore architecture. Some of our sites use the same domain with different virtual folders. I was surprised that the Layout Service can not resolve a virtual directory by default. Sitecore recommends to always populate sc_site parameter in the calls to Layout Service to use this technique. But, if you have more than one JSS app, you have to add additional code to extend the Layout Service call with the query string parameter.

I prefer another way. I extended the Sitecore SiteResolver:

Here is an image to clarify what has changed:

Then we need to patch the configuration to override the default Sitecore Site Resolver:

Take into account that the previously known RisolveSite processor is not used anymore:

To sum up, this solution relieves the necessity to think about resolving virtual directory for each JSS app and have this fixed once for the whole installation.