12
12
using Microsoft . Extensions . Configuration ;
13
13
using Microsoft . Extensions . DependencyInjection ;
14
14
using Microsoft . IdentityModel . Tokens ;
15
+ using Microsoft . OpenApi . Models ;
15
16
using Swashbuckle . AspNetCore . Swagger ;
16
17
17
18
public class Startup
@@ -40,16 +41,22 @@ public void ConfigureServices(IServiceCollection services)
40
41
} ) ;
41
42
AuthConfigurer . Configure ( services , Configuration ) ;
42
43
44
+ var origins = Configuration . GetSection ( "CorsUrls" ) . Value . Split ( "," ) ;
43
45
services . AddCors ( options => options . AddPolicy ( _defaultCorsPolicyName ,
44
46
builder =>
45
- builder . AllowAnyOrigin ( )
47
+ builder . WithOrigins ( origins )
46
48
. AllowAnyHeader ( )
47
49
. AllowAnyMethod ( ) . AllowCredentials ( )
48
50
) ) ;
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
+ } ) ; ;
50
57
services . AddSwaggerGen ( c =>
51
58
{
52
- c . SwaggerDoc ( "v1" , new Info { Title = "APIJSON.NET" , Version = "v1" } ) ;
59
+ c . SwaggerDoc ( "v1" , new OpenApiInfo { Title = "APIJSON.NET" , Version = "v1" } ) ;
53
60
} ) ;
54
61
services . AddSingleton < DbContext > ( ) ;
55
62
services . AddSingleton < SelectTable > ( ) ;
@@ -61,17 +68,12 @@ public void ConfigureServices(IServiceCollection services)
61
68
}
62
69
63
70
// 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 )
65
72
{
66
73
67
74
app . UseAuthentication ( ) ;
68
75
69
- app . UseMvc ( routes =>
70
- {
71
- routes . MapRoute (
72
- name : "default" ,
73
- template : "{controller=Home}/{action=Index}/{id?}" ) ;
74
- } ) ;
76
+ app . UseRouting ( ) ;
75
77
app . UseStaticFiles ( ) ;
76
78
app . UseCors ( _defaultCorsPolicyName ) ;
77
79
app . UseSwagger ( ) ;
@@ -80,7 +82,10 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
80
82
c . SwaggerEndpoint ( "/swagger/v1/swagger.json" , "My API V1" ) ;
81
83
82
84
} ) ;
83
-
85
+ app . UseEndpoints ( endpoints =>
86
+ {
87
+ endpoints . MapControllers ( ) ;
88
+ } ) ;
84
89
app . UseJwtTokenMiddleware ( ) ;
85
90
DbInit . Initialize ( app ) ;
86
91
}
0 commit comments