DD.WellWorkover.Cloud/AsbCloudWebApi/Startup.cs

110 lines
3.5 KiB
C#

using AsbCloudApp.Services;
using AsbCloudInfrastructure;
using AsbCloudWebApi.Middlewares;
using AsbCloudWebApi.SignalR;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace AsbCloudWebApi
{
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers()
.AddJsonOptions(new System.Action<Microsoft.AspNetCore.Mvc.JsonOptions>(opts =>
{
opts.JsonSerializerOptions.NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals | System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString;
}))
.AddProtoBufNet(); //adds mediaType "application/protobuf"
ProtobufModel.EnshureRegistered();
services.AddSwagger();
services.AddInfrastructure(Configuration);
services.AddJWTAuthentication();
services.AddSignalR();
services.AddCors(options =>
{
options.AddPolicy("ClientPermission", policy =>
{
policy.AllowAnyHeader()
.AllowAnyMethod()
.WithOrigins(
"http://0.0.0.0:3000",
"http://*:3000",
"http://localhost:3000",
"http://0.0.0.0:5000",
"http://*:5000",
"http://localhost:5000",
"https://0.0.0.0:3000",
"https://*:3000",
"https://localhost:3000",
"https://0.0.0.0:5001",
"https://*:5001",
"https://localhost:5001"
)
.AllowCredentials();
});
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "V1");
});
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
//app.UseHttpsRedirection();
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseCors("ClientPermission");
app.UseRouting();
app.UseResponseCaching();
//app.UseResponseCompression();
app.UseAuthentication();
app.UseAuthorization();
app.UseMiddleware<PermissionsMiddlware>();
app.UseMiddleware<SimplifyExceptionsMiddleware>();
app.UseMiddleware<RequerstTrackerMiddleware>();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHub<TelemetryHub>("/hubs/telemetry");
endpoints.MapHub<ReportsHub>("/hubs/reports");
});
app.UseSpa(spa =>
{
spa.Options.SourcePath = "wwwroot";
});
}
}
}