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.
But I prefer another way. I extended the Sitecore SiteResolver. I have got the original Sitecore SiteResolver and extended it by adding the following code:
var filePath = args.Url.FilePath;
if (uri.AbsolutePath.StartsWith("/sitecore/api/layout"))
{
string query = uri.Query;
var queryDictionary = System.Web.HttpUtility.ParseQueryString(query);
var itemProperty = queryDictionary["item"];
filePath = itemProperty ?? "/";
}
Look at the following screenshot to compare the updated site resolver with an original one:
Then you have to patch the configuration:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<preAuthenticateRequest>
<processor type="#your-namespace#.CustomSiteResolving, #your-assambly-name#"
patch:instead="*[@type='Sitecore.Pipelines.PreAuthenticateRequest.SiteResolver, Sitecore.Kernel']"
resolve="true"/>
</preAuthenticateRequest>
</pipelines>
</sitecore>
</configuration>
Take into account that you have to patch the Sitecore.Pipelines.PreAuthenticateRequest.SiteResolver
. So the previously known Sitecore.Pipelines.HttpRequest.RisolveSite
processor is not used anymore.