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;
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:
<processor type="#your-namespace#.CustomSiteResolving, #your-assambly-name#"
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.