diff --git a/AspNetCore/Vue2/AdvancedSearch/EqDemo.AspNetCoreVue2.AdvancedSearch.csproj b/AspNetCore/Vue2/AdvancedSearch/EqDemo.AspNetCoreVue2.AdvancedSearch.csproj index b84cd155..658e98e5 100644 --- a/AspNetCore/Vue2/AdvancedSearch/EqDemo.AspNetCoreVue2.AdvancedSearch.csproj +++ b/AspNetCore/Vue2/AdvancedSearch/EqDemo.AspNetCoreVue2.AdvancedSearch.csproj @@ -1,25 +1,26 @@ - net6.0 + net8.0 3.0 ClientApp\ $(DefaultItemExcludes);$(SpaRoot)node_modules\** EqDemo.AspNetCoreVue.AdvancedSearch true + npm run serve -- --port 8085 + http://localhost:8085 - - - + + + - + - - - + + @@ -58,11 +59,11 @@ - + %(DistFiles.Identity) PreserveNewest - \ No newline at end of file + diff --git a/AspNetCore/Vue2/AdvancedSearch/Properties/launchSettings.json b/AspNetCore/Vue2/AdvancedSearch/Properties/launchSettings.json index c990ef22..39e7bd35 100644 --- a/AspNetCore/Vue2/AdvancedSearch/Properties/launchSettings.json +++ b/AspNetCore/Vue2/AdvancedSearch/Properties/launchSettings.json @@ -12,16 +12,18 @@ "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy" } }, "EqVueDemo": { "commandName": "Project", "launchBrowser": true, "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy" }, "applicationUrl": "https://localhost:5001;http://localhost:5000" } } -} \ No newline at end of file +} diff --git a/AspNetCore/Vue2/AdvancedSearch/Startup.cs b/AspNetCore/Vue2/AdvancedSearch/Startup.cs index e1fcb214..ab502da3 100644 --- a/AspNetCore/Vue2/AdvancedSearch/Startup.cs +++ b/AspNetCore/Vue2/AdvancedSearch/Startup.cs @@ -1,14 +1,14 @@ using System; +using System.IO; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Hosting; using Microsoft.EntityFrameworkCore; -using VueCliMiddleware; - using Korzh.EasyQuery.Services; using EasyData.Export; @@ -44,12 +44,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/dist"; - }); - services.AddEasyQuery() .UseSqlManager() .AddDefaultExporters() @@ -77,11 +71,17 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseCors("AllowAllPolicy"); app.UseHttpsRedirection(); - app.UseStaticFiles(); - if (!env.IsDevelopment()) { - app.UseSpaStaticFiles(); + + // Serve Vue SPA build output from ClientApp/dist in production + var spaPath = Path.Combine(env.ContentRootPath, "ClientApp", "dist"); + if (Directory.Exists(spaPath)) { + var fileProvider = new PhysicalFileProvider(spaPath); + app.UseDefaultFiles(new DefaultFilesOptions { FileProvider = fileProvider }); + app.UseStaticFiles(new StaticFileOptions { FileProvider = fileProvider }); } + app.UseStaticFiles(); + app.UseRouting(); @@ -103,24 +103,15 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) endpoints.MapControllerRoute( name: "default", pattern: "{controller}/{action=Index}/{id?}"); - }); - app.UseSpa(spa => - { - spa.Options.SourcePath = "ClientApp"; - spa.Options.StartupTimeout = TimeSpan.FromMinutes(2); - - if (env.IsDevelopment()) - { - // run npm process with client app - spa.UseVueCli(npmScript: "serve", port: 8085, regex: "Compiled "); - // if you just prefer to proxy requests from client app, use proxy to SPA dev server instead: - // app should be already running before starting a .NET client - // spa.UseProxyToSpaDevelopmentServer("http://localhost:8080"); // your Vue app port + if (Directory.Exists(Path.Combine(env.ContentRootPath, "ClientApp", "dist"))) { + endpoints.MapFallbackToFile("index.html", new StaticFileOptions { + FileProvider = new PhysicalFileProvider( + Path.Combine(env.ContentRootPath, "ClientApp", "dist")) + }); } }); - //Init demo database (if necessary) app.EnsureDbInitialized(Configuration, env); }