1212 using Microsoft . Extensions . Configuration ;
1313 using Microsoft . Extensions . DependencyInjection ;
1414 using Microsoft . IdentityModel . Tokens ;
15+ using Microsoft . OpenApi . Models ;
1516 using Swashbuckle . AspNetCore . Swagger ;
1617
1718 public class Startup
@@ -40,16 +41,22 @@ public void ConfigureServices(IServiceCollection services)
4041 } ) ;
4142 AuthConfigurer . Configure ( services , Configuration ) ;
4243
44+ var origins = Configuration . GetSection ( "CorsUrls" ) . Value . Split ( "," ) ;
4345 services . AddCors ( options => options . AddPolicy ( _defaultCorsPolicyName ,
4446 builder =>
45- builder . AllowAnyOrigin ( )
47+ builder . WithOrigins ( origins )
4648 . AllowAnyHeader ( )
4749 . AllowAnyMethod ( ) . AllowCredentials ( )
4850 ) ) ;
49- services . AddMvc ( ) . SetCompatibilityVersion ( CompatibilityVersion . Version_2_1 ) ;
51+ services . AddControllers ( )
52+ . AddNewtonsoftJson ( options =>
53+ {
54+ options . SerializerSettings . ReferenceLoopHandling = Newtonsoft . Json . ReferenceLoopHandling . Ignore ;
55+ options . SerializerSettings . DateFormatString = "yyyy-MM-dd HH:mm:ss" ;
56+ } ) ; ;
5057 services . AddSwaggerGen ( c =>
5158 {
52- c . SwaggerDoc ( "v1" , new Info { Title = "APIJSON.NET" , Version = "v1" } ) ;
59+ c . SwaggerDoc ( "v1" , new OpenApiInfo { Title = "APIJSON.NET" , Version = "v1" } ) ;
5360 } ) ;
5461 services . AddSingleton < DbContext > ( ) ;
5562 services . AddSingleton < SelectTable > ( ) ;
@@ -61,17 +68,12 @@ public void ConfigureServices(IServiceCollection services)
6168 }
6269
6370 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
64- public void Configure ( IApplicationBuilder app , IHostingEnvironment env )
71+ public void Configure ( IApplicationBuilder app , IWebHostEnvironment env )
6572 {
6673
6774 app . UseAuthentication ( ) ;
6875
69- app . UseMvc ( routes =>
70- {
71- routes . MapRoute (
72- name : "default" ,
73- template : "{controller=Home}/{action=Index}/{id?}" ) ;
74- } ) ;
76+ app . UseRouting ( ) ;
7577 app . UseStaticFiles ( ) ;
7678 app . UseCors ( _defaultCorsPolicyName ) ;
7779 app . UseSwagger ( ) ;
@@ -80,7 +82,10 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
8082 c . SwaggerEndpoint ( "/swagger/v1/swagger.json" , "My API V1" ) ;
8183
8284 } ) ;
83-
85+ app . UseEndpoints ( endpoints =>
86+ {
87+ endpoints . MapControllers ( ) ;
88+ } ) ;
8489 app . UseJwtTokenMiddleware ( ) ;
8590 DbInit . Initialize ( app ) ;
8691 }
0 commit comments