diff options
author | 杨宇千 <crupest@outlook.com> | 2019-05-06 14:22:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-06 14:22:10 +0800 |
commit | ea84a067eee6dcd10dd0bc89967ef608677ef37e (patch) | |
tree | 37c2b6f9dcb3d6f57867ebc7538523d1a338183d /Timeline/Startup.cs | |
parent | ae848e311b46a25ec1ed571432d55e800ac7595b (diff) | |
parent | 070a4a8399201150a633c80608a13cc44781a3c4 (diff) | |
download | timeline-ea84a067eee6dcd10dd0bc89967ef608677ef37e.tar.gz timeline-ea84a067eee6dcd10dd0bc89967ef608677ef37e.tar.bz2 timeline-ea84a067eee6dcd10dd0bc89967ef608677ef37e.zip |
Merge pull request #22 from crupest/user-admin
Develop user management feature.
Diffstat (limited to 'Timeline/Startup.cs')
-rw-r--r-- | Timeline/Startup.cs | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs index 0c8d7052..46d0afe5 100644 --- a/Timeline/Startup.cs +++ b/Timeline/Startup.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.IdentityModel.Tokens; @@ -36,26 +37,16 @@ namespace Timeline options.InputFormatters.Add(new StringInputFormatter()); }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2); - if (Environment.IsDevelopment()) + services.AddCors(options => { - services.AddCors(options => + options.AddPolicy(corsPolicyName, builder => { - options.AddPolicy(corsPolicyName, builder => - { - builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials(); - }); - }); - } - else - { - services.AddCors(options => - { - options.AddPolicy(corsPolicyName, builder => - { + if (Environment.IsProduction()) builder.WithOrigins("https://www.crupest.xyz", "https://crupest.xyz").AllowAnyMethod().AllowAnyHeader().AllowCredentials(); - }); + else + builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials(); }); - } + }); services.Configure<JwtConfig>(Configuration.GetSection(nameof(JwtConfig))); var jwtConfig = Configuration.GetSection(nameof(JwtConfig)).Get<JwtConfig>(); @@ -80,22 +71,25 @@ namespace Timeline services.AddDbContext<DatabaseContext>(options => { - options.UseMySql(databaseConfig.ConnectionString); + options.UseMySql(databaseConfig.ConnectionString) + .ConfigureWarnings(warnings => + { + if (Environment.IsProduction()) + warnings.Log(RelationalEventId.QueryClientEvaluationWarning); + else + warnings.Throw(RelationalEventId.QueryClientEvaluationWarning); + }); }); + + services.AddHttpClient(); + + services.Configure<QCloudCosConfig>(Configuration.GetSection(nameof(QCloudCosConfig))); + services.AddSingleton<IQCloudCosService, QCloudCosService>(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app) { - if (Environment.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - else - { - app.UseExceptionHandler("/Error"); - } - app.UseCors(corsPolicyName); app.UseForwardedHeaders(new ForwardedHeadersOptions |