Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ReactJs.Net in multisite solution #1273

Open
RadikFayskhanov opened this issue Nov 17, 2021 · 0 comments
Open

Using ReactJs.Net in multisite solution #1273

RadikFayskhanov opened this issue Nov 17, 2021 · 0 comments

Comments

@RadikFayskhanov
Copy link

RadikFayskhanov commented Nov 17, 2021

I'm using these library versions:

  • ReactJS.NET: 5.2.11
  • JavaScriptEngineSwitcher: V8 3.5.5
  • react and react-dom: (N/A if using bundled react, or version number)
  • webpack: bundled webpack
  • node: (N/A if using bundled react)

Runtime environment:

  • OS: Windows 10
  • .NET Framework 4.8

Hi guys!
We are having issues with configuring the react.NET library for the multisite solution. We are using Sitecore CMS where there are multiple sites configured within one app domain in .NET. Each site has its own front-end build with a separate output path, i.e. '~/dist/'. At the moment we are using the following code to configure react.NET:

public class ReactJsNetRequestHandler : HttpRequestProcessor
{
        private static readonly IDictionary<string, string> ReactPaths = new Dictionary<string, string>
        {
            { "SiteOne", "~/dist/siteOne" },
            { "SiteTwo", "~/dist/siteTwo" }
        };

        public override void Process(HttpRequestArgs args)
        {
            if (Sitecore.Context.Site == null || !ReactPaths.ContainsKey(Sitecore.Context.Site.Name))
                return;

            var reactPath = ReactPaths[Sitecore.Context.Site.Name];
            Configure(reactPath);
        }

        private static void Configure(string path)
        {
            ReactSiteConfiguration.Configuration
                .SetLoadBabel(false)
                .SetLoadReact(false)
                .SetReactAppBuildPath(path)
                ;

            JsEngineSwitcher.Current.DefaultEngineName = V8JsEngine.EngineName;
            JsEngineSwitcher.Current.EngineFactories.AddV8();
        }
}

The issue with the current code is it only works with the first initialized site, all subsequent sites are unable to find JSX resources.

Is it possible to have multiple configurations or dynamically loaded configurations?

Best regards, Radik.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant