99using Microsoft . Extensions . Logging ;
1010using Microsoft . Extensions . Options ;
1111using Microsoft . EntityFrameworkCore ;
12- using Microsoft . Data . Edm ;
1312using Microsoft . AspNet . OData . Builder ;
1413using Microsoft . AspNet . OData . Extensions ;
1514using Microsoft . AspNetCore . Routing ;
1918using Syncfusion . EJ2 . SpellChecker ;
2019using System . IO ;
2120using Newtonsoft . Json ;
21+ using Newtonsoft . Json . Serialization ;
22+ using Microsoft . AspNetCore . ResponseCompression ;
2223
2324namespace EJ2DocumentEditorServer
2425{
@@ -63,27 +64,30 @@ public Startup(IConfiguration configuration, IHostingEnvironment env)
6364 }
6465
6566 public IConfiguration Configuration { get ; }
66-
67+ readonly string MyAllowSpecificOrigins = "MyPolicy" ;
6768 // This method gets called by the runtime. Use this method to add services to the container.
6869 public void ConfigureServices ( IServiceCollection services )
6970 {
70- services . AddOData ( ) ;
71- services . AddMvc ( ) . AddJsonOptions ( x => {
72- x . SerializerSettings . ContractResolver = null ;
71+ services . AddControllers ( ) ;
72+ services . AddMemoryCache ( ) ;
73+ services . AddControllers ( ) . AddNewtonsoftJson ( options =>
74+ {
75+ // Use the default property (Pascal) casing
76+ options . SerializerSettings . ContractResolver = new DefaultContractResolver ( ) ;
7377 } ) ;
7478
7579 services . AddCors ( options =>
7680 {
77- options . AddPolicy ( "AllowAllOrigins" , builder =>
81+ options . AddPolicy ( MyAllowSpecificOrigins ,
82+ builder =>
7883 {
7984 builder . AllowAnyOrigin ( )
80- . AllowAnyMethod ( )
81- . AllowAnyHeader ( ) ;
85+ . AllowAnyMethod ( )
86+ . AllowAnyHeader ( ) ;
8287 } ) ;
8388 } ) ;
84-
85- // Add framework services.
86- services . AddMvc ( ) ;
89+ services . Configure < GzipCompressionProviderOptions > ( options => options . Level = System . IO . Compression . CompressionLevel . Optimal ) ;
90+ services . AddResponseCompression ( ) ;
8791 }
8892
8993 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -98,10 +102,18 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
98102 {
99103 app . UseDeveloperExceptionPage ( ) ;
100104 }
101-
102- app . UseMvc ( routes =>
105+ else
106+ {
107+ app . UseHsts ( ) ;
108+ }
109+ app . UseHttpsRedirection ( ) ;
110+ app . UseRouting ( ) ;
111+ app . UseAuthorization ( ) ;
112+ app . UseCors ( MyAllowSpecificOrigins ) ;
113+ app . UseResponseCompression ( ) ;
114+ app . UseEndpoints ( endpoints =>
103115 {
104- routes . MapRoute ( "default" , "{api}/{controller}/{action}/{id?} ") ;
116+ endpoints . MapControllers ( ) . RequireCors ( "MyPolicy ") ;
105117 } ) ;
106118 }
107119
0 commit comments