I've come up with a solution that's working for me, based on the answer by @cminus.
First, I created this helper function, where codeFolderPath
is the where my app folder is, and spaPath
is the directory where I want the application hosted:
private void EnableReactApp(IApplicationBuilder app, IWebHostEnvironment env, string codeFolderPath, string spaPath) { if (env.IsDevelopment()) { app.MapWhen(y => y.Request.Path.StartsWithSegments(spaPath) || y.Request.Path.StartsWithSegments("/sockjs-node") || y.Request.Path.StartsWithSegments("/static"), client => { client.UseSpa(spa => { spa.Options.SourcePath = codeFolderPath; spa.UseReactDevelopmentServer(npmScript: "start"); }); }); } else { app.Map(new PathString(spaPath), client => { client.UsePathBase(new PathString(spaPath)); client.UseSpaStaticFiles(); client.UseSpa(spa => { spa.Options.SourcePath = codeFolderPath;}); }); } }
Then, I add the following lines to my Startup.cs
:
public void ConfigureServices(IServiceCollection services) { [...] services.AddSpaStaticFiles(configuration => { configuration.RootPath = "SpaApp1/build"; }); services.AddSpaStaticFiles(configuration => { configuration.RootPath = "SpaApp2/build"; }); [...] } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { [...] EnableReactApp(app, env, "SpaApp1", "/admin"); EnableReactApp(app, env, "SpaApp2", "/sandbox"); [...] }