123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using GxPress.Api.ServiceExtensions;
- using GxPress.Common.AppOptions;
- using GxPress.Common.Middleware;
- using GxPress.Common.Tools;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http.Features;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Hosting;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Serialization;
- using Quartz;
- using Quartz.Impl;
- namespace GxPress.Api
- {
- public class Startup
- {
- public IConfiguration Configuration { get; }
- public Startup(IConfiguration configuration)
- {
- Configuration = configuration;
- ConfigHelper.Configs = Configuration;
- }
-
-
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
- services.AddControllers().AddNewtonsoftJson(options =>
- {
- options.SerializerSettings.ContractResolver = new DefaultContractResolver();
-
- options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
-
-
-
-
- }).AddJsonOptions(options =>
- {
- options.JsonSerializerOptions.PropertyNamingPolicy = null;
- }).SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
-
- services.Configure<FormOptions>(options =>
- {
- options.MultipartBodyLengthLimit = 60000000;
- });
-
- var databaseSection = Configuration.GetSection("Database");
- var cacheSection = Configuration.GetSection("Cache:ConnectionString");
- var storageOptions = Configuration.GetSection("Storage").Get<StorageOptions>();
- services.Configure<DatabaseOptions>(databaseSection);
- services.AddDistributedCache(cacheSection.Value);
- services.AddStorage(storageOptions);
- services.Configure<ApiBehaviorOptions>(o =>
- {
- o.InvalidModelStateResponseFactory = actionContext =>
- new BadRequestObjectResult(JsonConvert.SerializeObject(new
- {
- Message = "参数错误",
- StackTrace = JsonConvert.SerializeObject(actionContext.ModelState)
- }));
- });
-
-
-
-
-
-
-
-
-
-
- services.AddRepositories();
- services.AddServices();
- services.AddMappers();
- services.AddJwtAuthentication(Configuration);
- services.AddCors(options =>
- {
- options.AddPolicy(
- "AllowAny",
- x =>
- {
- x.AllowAnyHeader()
- .AllowAnyMethod()
- .SetIsOriginAllowed(_ => true)
- .AllowCredentials();
- });
- });
- services.AddSwashbuckle();
- }
-
- public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
-
- app.UseMiddleware<ExceptionMiddleware>();
- app.UseRouting();
- app.UseJwtAuthorization();
- app.UseStaticFiles();
- app.UseCors("AllowAny");
- app.UseSwashbuckle();
- app.UseEndpoints(endpoints =>
- {
- endpoints.MapControllers();
- endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
- });
- }
- }
- }
|