1- using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Threading . Tasks ;
1+ using System . IO . Compression ;
2+ using AspDotnetVueJS . Extensions ;
53using Microsoft . AspNetCore . Builder ;
64using Microsoft . AspNetCore . Hosting ;
7- using Microsoft . AspNetCore . HttpsPolicy ;
85using Microsoft . AspNetCore . Mvc ;
6+ using Microsoft . AspNetCore . ResponseCompression ;
7+ using Microsoft . AspNetCore . SpaServices . Webpack ;
98using Microsoft . Extensions . Configuration ;
109using Microsoft . Extensions . DependencyInjection ;
11- using Microsoft . Extensions . Logging ;
12- using Microsoft . Extensions . Options ;
1310
1411namespace AspDotnetVueJS
1512{
@@ -26,6 +23,21 @@ public Startup(IConfiguration configuration)
2623 public void ConfigureServices ( IServiceCollection services )
2724 {
2825 services . AddMvc ( ) . SetCompatibilityVersion ( CompatibilityVersion . Version_2_2 ) ;
26+
27+ // Enable the Gzip compression especially for Kestrel
28+ services . Configure < GzipCompressionProviderOptions > ( options =>
29+ options . Level = CompressionLevel . Optimal ) ;
30+ services . AddResponseCompression ( options =>
31+ {
32+ #if ( ! NoHttps )
33+ options . EnableForHttps = true ;
34+ #endif
35+ } ) ;
36+
37+ services . AddSpaStaticFiles ( config => { config . RootPath = "wwwroot/" ; } ) ;
38+
39+ // Example with dependency injection for a data provider.
40+ services . AddWeather ( ) ;
2941 }
3042
3143 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -37,12 +49,44 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
3749 }
3850 else
3951 {
40- // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
52+ app . UseExceptionHandler ( "/Error" ) ;
53+ #if ( ! NoHttps )
4154 app . UseHsts ( ) ;
4255 }
4356
4457 app . UseHttpsRedirection ( ) ;
45- app . UseMvc ( ) ;
58+ #else
59+ }
60+ #endif
61+
62+ app . UseResponseCompression ( ) ; // No need if you use IIS, but really something good for Kestrel!
63+
64+ // Idea: https://code.msdn.microsoft.com/How-to-fix-the-routing-225ac90f
65+ // This avoid having a real mvc view. You have other way of doing, but this one works
66+ // properly.
67+ // app.UseSpa();
68+ app . UseDefaultFiles ( ) ;
69+ app . UseStaticFiles ( ) ;
70+ app . UseSpaStaticFiles ( ) ;
71+ app . UseMvc ( routes =>
72+ {
73+ routes . MapRoute (
74+ "default" ,
75+ "{controller}/{action=Index}/{id?}" ) ;
76+ } ) ;
77+
78+ app . UseSpa ( spa =>
79+ {
80+ spa . Options . SourcePath = "ClientApp" ;
81+
82+ if ( env . IsDevelopment ( ) )
83+ spa . ApplicationBuilder . UseWebpackDevMiddleware (
84+ new WebpackDevMiddlewareOptions
85+ {
86+ HotModuleReplacement = true ,
87+ ConfigFile = "./build/webpack.config.js"
88+ } ) ;
89+ } ) ;
4690 }
4791 }
48- }
92+ }
0 commit comments