diff --git a/AspNetCoreVueStarter.csproj b/AspNetCoreVueStarter.csproj index bba42cf..423d077 100644 --- a/AspNetCoreVueStarter.csproj +++ b/AspNetCoreVueStarter.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 true Latest false @@ -19,8 +19,8 @@ - - + + diff --git a/Program.cs b/Program.cs index 02c949f..f874b64 100644 --- a/Program.cs +++ b/Program.cs @@ -17,14 +17,61 @@ public static void Main(string[] args) return; } - CreateHostBuilder(args).Build().Run(); - } + var builder = WebApplication.CreateBuilder(args); + builder.Services.AddControllersWithViews(); + builder.Services.AddSpaStaticFiles(configuration => + { + configuration.RootPath = "ClientApp/dist"; + }); + + var app = builder.Build(); + + if (app.Environment.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + app.UseExceptionHandler("/Error"); + app.UseHsts(); + } + + if (https) app.UseHttpsRedirection(); + + app.UseStaticFiles(); + if (!app.Environment.IsDevelopment()) + { + app.UseSpaStaticFiles(); + } + + app.UseRouting(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllerRoute( + name: "default", + pattern: "{controller}/{action=Index}/{id?}"); + }); + + app.UseSpa(spa => + { + spa.Options.SourcePath = "ClientApp"; - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => + if (app.Environment.IsDevelopment()) { - webBuilder.UseStartup(); - }); + if (mode == "start") + { + spa.UseVueCli(npmScript: "serve", port: port, forceKill: true, https: https); + } + + if (mode == "attach") + { + spa.UseProxyToSpaDevelopmentServer($"{(https ? "https" : "http")}://localhost:{port}"); + } + } + }); + + app.Run(); + } } } diff --git a/README.md b/README.md index d6086f3..9a59fad 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ASP.NET Core Vue Starter -The repository contains an ASP.​NET Core + Vue.js starter template. The template runs on ASP.NET Core 5.0 and is created by Vue CLI 4.0 with a new plugin based architecture allowing developers to interactively scaffold a new project with just a one command. +The repository contains an ASP.​NET Core + Vue.js starter template. The template runs on ASP.NET Core 6.0 and is created by Vue CLI 4.0 with a new plugin based architecture allowing developers to interactively scaffold a new project with just a one command. Original article how to create the starter template is available [here](https://medium.com/software-ateliers/asp-net-core-vue-template-with-custom-configuration-using-cli-3-0-8288e18ae80b). @@ -28,7 +28,7 @@ Original article how to create the starter template is available [here](https:// ## Used Technology Stack -**ASP.NET Core 5.0:** +**ASP.NET Core 6.0:** * Web.API * Vue CLI and JavaScript Services middlewares to integrate with client app @@ -46,7 +46,7 @@ Original article how to create the starter template is available [here](https:// ## Prerequisites -* [.NET Core](https://www.microsoft.com/net/download/windows) >= 5.0 +* [.NET Core](https://www.microsoft.com/net/download/windows) >= 6.0 * [NodeJS](https://nodejs.org/) >= 8.9 * [Vue CLI](https://cli.vuejs.org/) >= 4.0 * Your favourite editor (I prefer [VS Code](https://code.visualstudio.com/)), or VS 2017/19 @@ -159,4 +159,4 @@ Copyright © 2018 - 2022 [Software Ateliers](https://github.com/SoftwareAtel ## Where to find me -Medium: [Software Ateliers](https://medium.com/software-ateliers) | Twitter: [@SAteliers](https://twitter.com/SAteliers) \ No newline at end of file +Medium: [Software Ateliers](https://medium.com/software-ateliers) | Twitter: [@SAteliers](https://twitter.com/SAteliers)