DD.WellWorkover.Cloud/AsbCloudWebApi/Startup.cs

158 lines
5.2 KiB
C#
Raw Permalink Normal View History

using AsbCloudInfrastructure;
using AsbCloudWebApi.Converters;
using AsbCloudWebApi.Middlewares;
using AsbCloudWebApi.SignalR;
using AsbCloudWebApi.SignalR.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Mvc;
2023-05-24 17:09:25 +05:00
using Microsoft.AspNetCore.ResponseCompression;
using AsbCloudWebApi.Conventions;
2024-08-19 10:01:07 +05:00
namespace AsbCloudWebApi;
public class Startup
{
2024-08-19 10:01:07 +05:00
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
2024-08-19 10:01:07 +05:00
Configuration = configuration;
}
2024-08-19 10:01:07 +05:00
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers()
.AddJsonOptions(new System.Action<JsonOptions>(options =>
{
options.JsonSerializerOptions.NumberHandling =
System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals |
System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString;
2024-08-19 10:01:07 +05:00
options.JsonSerializerOptions.Converters.Add(new DateOnlyJsonConverter());
options.JsonSerializerOptions.Converters.Add(new JsonValueJsonConverter());
}))
.AddProtoBufNet();
2024-08-19 10:01:07 +05:00
services.AddControllers(options => options.UseDateOnlyTimeOnlyStringConverters());
2024-08-19 10:01:07 +05:00
ProtobufModel.EnsureRegistered();
2024-08-19 10:01:07 +05:00
services.AddSwagger();
2022-06-15 14:57:37 +05:00
2024-08-19 10:01:07 +05:00
services.AddInfrastructure(Configuration);
services.AddNotificationTransportServices();
2024-08-19 10:01:07 +05:00
services.AddIntegrationEvents();
2024-08-19 10:01:07 +05:00
services.AddJWTAuthentication();
2021-04-08 17:54:02 +05:00
2024-08-19 10:01:07 +05:00
services.AddSignalR()
.Services.AddSingleton<ConnectionManagerService>();
2021-04-08 17:54:02 +05:00
2024-08-19 10:01:07 +05:00
services.AddCors(options =>
{
options.AddPolicy("ClientPermission", policy =>
2021-04-08 17:54:02 +05:00
{
2024-08-19 10:01:07 +05:00
policy.AllowAnyHeader()
.AllowAnyMethod()
.WithOrigins(
"http://0.0.0.0",
"http://*",
"http://localhost",
"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",
"https://*",
"https://localhost",
"https://0.0.0.0:3000",
"https://*:3000",
"https://localhost:3000",
"https://0.0.0.0:5001",
"https://*:5001",
"https://localhost:5001",
"https://0.0.0.0:443",
"https://*:443",
"https://localhost:443",
"http://cloud.autodrilling.ru",
"http://cloud.digitaldrilling.ru",
"http://test.digitaldrilling.ru",
"https://cloud.autodrilling.ru",
"https://cloud.digitaldrilling.ru",
"https://testdigitaldrilling.ru",
"smb2-digital-drilling-frontend-smb2-dev.apps.okd.cloud.nedra.digital",
"http://smb2-digital-drilling-frontend-smb2-dev.apps.okd.cloud.nedra.digital",
"https://smb2-digital-drilling-frontend-smb2-dev.apps.okd.cloud.nedra.digital"
)
.AllowCredentials();
2021-04-08 17:54:02 +05:00
});
2024-08-19 10:01:07 +05:00
});
2024-08-19 10:01:07 +05:00
services.AddResponseCompression(options =>
{
options.EnableForHttps = true;
options.Providers.Add<GzipCompressionProvider>();
});
2024-08-19 10:01:07 +05:00
services.AddMvc(c =>
c.Conventions.Add(new ApiExplorerGroupPerVersionConvention())
);
}
2024-08-19 10:01:07 +05:00
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
2024-08-19 10:01:07 +05:00
c.SwaggerEndpoint("/swagger/v1/swagger.json", "V1");
c.SwaggerEndpoint("/swagger/signalr/swagger.json", "signalr");
c.EnablePersistAuthorization();
c.EnableFilter();
c.DisplayOperationId();
});
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
2024-08-19 10:01:07 +05:00
app.UseCors("ClientPermission");
app.UseRouting();
2024-08-19 10:01:07 +05:00
app.UseResponseCaching();
app.UseResponseCompression();
2022-04-11 18:00:34 +05:00
2024-08-19 10:01:07 +05:00
app.UseAuthentication();
app.UseAuthorization();
2024-08-19 10:01:07 +05:00
app.UseMiddleware<PermissionsMiddlware>(Configuration);
app.UseMiddleware<SimplifyExceptionsMiddleware>();
app.UseMiddleware<RequerstTrackerMiddleware>();
2024-08-19 10:01:07 +05:00
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHub<WellInfoHub>("/hubs/wellInfo");
endpoints.MapHub<NotificationHub>("/hubs/notifications");
endpoints.MapHub<TelemetryHub>("/hubs/telemetry");
endpoints.MapHub<ReportsHub>("/hubs/reports");
});
}
}