diff --git a/AspNetCore/React/AdvancedSearch/EqDemo.AspNetCoreReact.AdvancedSearch.csproj b/AspNetCore/React/AdvancedSearch/EqDemo.AspNetCoreReact.AdvancedSearch.csproj index 40bb9e61..0e3a5176 100644 --- a/AspNetCore/React/AdvancedSearch/EqDemo.AspNetCoreReact.AdvancedSearch.csproj +++ b/AspNetCore/React/AdvancedSearch/EqDemo.AspNetCoreReact.AdvancedSearch.csproj @@ -1,69 +1,71 @@ - - - net6.0 - true - Latest - false - ClientApp\ - $(DefaultItemExcludes);$(SpaRoot)node_modules\** - EqDemo.AspNetCoreReact.AdvancedSearch - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %(DistFiles.Identity) - PreserveNewest - - - - \ No newline at end of file + + + net8.0 + true + Latest + false + ClientApp\ + + http://localhost:3000 + npm start + $(DefaultItemExcludes);$(SpaRoot)node_modules\** + EqDemo.AspNetCoreReact.AdvancedSearch + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + wwwroot\%(RecursiveDir)%(FileName)%(Extension) + PreserveNewest + true + + + + diff --git a/AspNetCore/React/AdvancedSearch/Properties/launchSettings.json b/AspNetCore/React/AdvancedSearch/Properties/launchSettings.json index d97e6c3f..85c90d61 100644 --- a/AspNetCore/React/AdvancedSearch/Properties/launchSettings.json +++ b/AspNetCore/React/AdvancedSearch/Properties/launchSettings.json @@ -12,7 +12,8 @@ "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy" } }, "EqReactDemo": { @@ -20,7 +21,8 @@ "launchBrowser": true, "applicationUrl": "https://localhost:5001;http://localhost:5000", "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy" } } } diff --git a/AspNetCore/React/AdvancedSearch/Startup.cs b/AspNetCore/React/AdvancedSearch/Startup.cs index 6ea66069..a4ab3390 100644 --- a/AspNetCore/React/AdvancedSearch/Startup.cs +++ b/AspNetCore/React/AdvancedSearch/Startup.cs @@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.DependencyInjection; @@ -43,12 +42,6 @@ public void ConfigureServices(IServiceCollection services) services.AddControllersWithViews(); - // In production, the React files will be served from this directory - services.AddSpaStaticFiles(configuration => - { - configuration.RootPath = "ClientApp/build"; - }); - services.AddEasyQuery() .UseSqlManager() .AddDefaultExporters() @@ -78,10 +71,9 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseCors("AllowAllPolicy"); app.UseHttpsRedirection(); + // In production, prebuilt SPA assets are copied into wwwroot by the + // PublishRunWebpack target and served via the default static-files middleware. app.UseStaticFiles(); - if (!env.IsDevelopment()) { - app.UseSpaStaticFiles(); - } app.UseRouting(); @@ -103,15 +95,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) endpoints.MapControllerRoute( name: "default", pattern: "{controller}/{action=Index}/{id?}"); - }); - - app.UseSpa(spa => - { - spa.Options.SourcePath = "ClientApp"; - if (env.IsDevelopment()) { - spa.UseReactDevelopmentServer(npmScript: "start"); - } + // SPA fallback: serve the prebuilt index.html for client-side routes in production. + // In Development the SPA is launched via Microsoft.AspNetCore.SpaProxy using the + // SpaProxyServerUrl/SpaProxyLaunchCommand MSBuild properties from the .csproj. + endpoints.MapFallbackToFile("index.html"); }); //Init demo database (if necessary)