2021-04-02 17:28:07 +05:00
|
|
|
using AsbCloudInfrastructure;
|
2023-03-06 16:30:36 +05:00
|
|
|
using AsbCloudWebApi.Converters;
|
2021-11-10 17:04:07 +05:00
|
|
|
using AsbCloudWebApi.Middlewares;
|
2021-04-09 17:59:07 +05:00
|
|
|
using AsbCloudWebApi.SignalR;
|
2021-04-02 17:28:07 +05:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Hosting;
|
2023-03-30 12:57:32 +05:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
|
|
namespace AsbCloudWebApi
|
|
|
|
{
|
|
|
|
public class Startup
|
|
|
|
{
|
2022-01-05 17:50:45 +05:00
|
|
|
public IConfiguration Configuration { get; }
|
2021-04-02 17:28:07 +05:00
|
|
|
public Startup(IConfiguration configuration)
|
|
|
|
{
|
|
|
|
Configuration = configuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
{
|
2021-09-13 11:02:54 +05:00
|
|
|
services.AddControllers()
|
2022-05-31 12:30:03 +05:00
|
|
|
.AddJsonOptions(new System.Action<Microsoft.AspNetCore.Mvc.JsonOptions>(options =>
|
2021-09-13 11:02:54 +05:00
|
|
|
{
|
2022-06-15 14:57:37 +05:00
|
|
|
options.JsonSerializerOptions.NumberHandling =
|
2022-06-06 17:00:53 +05:00
|
|
|
System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals |
|
2022-06-15 14:57:37 +05:00
|
|
|
System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString;
|
2023-03-06 16:30:36 +05:00
|
|
|
|
|
|
|
options.JsonSerializerOptions.Converters.Add(new DateOnlyJsonConverter());
|
2022-06-15 14:57:37 +05:00
|
|
|
}))
|
2022-05-31 12:30:03 +05:00
|
|
|
.AddProtoBufNet();
|
2021-10-31 16:35:09 +05:00
|
|
|
|
2023-03-30 12:57:32 +05:00
|
|
|
services.AddControllers(options => options.UseDateOnlyTimeOnlyStringConverters());
|
|
|
|
|
2021-10-31 16:35:09 +05:00
|
|
|
ProtobufModel.EnshureRegistered();
|
2021-04-02 17:28:07 +05:00
|
|
|
|
2021-05-20 11:17:55 +05:00
|
|
|
services.AddSwagger();
|
2022-06-15 14:57:37 +05:00
|
|
|
|
2021-04-02 17:28:07 +05:00
|
|
|
services.AddInfrastructure(Configuration);
|
|
|
|
|
2021-05-20 11:17:55 +05:00
|
|
|
services.AddJWTAuthentication();
|
2021-04-08 17:54:02 +05:00
|
|
|
|
|
|
|
services.AddSignalR();
|
|
|
|
|
|
|
|
services.AddCors(options =>
|
|
|
|
{
|
|
|
|
options.AddPolicy("ClientPermission", policy =>
|
|
|
|
{
|
|
|
|
policy.AllowAnyHeader()
|
|
|
|
.AllowAnyMethod()
|
2021-05-20 14:30:25 +05:00
|
|
|
.WithOrigins(
|
2022-04-22 17:26:03 +05:00
|
|
|
"http://0.0.0.0",
|
|
|
|
"http://*",
|
|
|
|
"http://localhost",
|
|
|
|
|
2021-05-20 14:30:25 +05:00
|
|
|
"http://0.0.0.0:3000",
|
2021-05-25 11:49:13 +05:00
|
|
|
"http://*:3000",
|
2021-05-20 14:30:25 +05:00
|
|
|
"http://localhost:3000",
|
2022-04-22 17:26:03 +05:00
|
|
|
|
2021-05-20 14:30:25 +05:00
|
|
|
"http://0.0.0.0:5000",
|
2021-05-25 11:49:13 +05:00
|
|
|
"http://*:5000",
|
2021-12-22 15:59:02 +05:00
|
|
|
"http://localhost:5000",
|
2022-04-22 17:26:03 +05:00
|
|
|
|
|
|
|
"https://0.0.0.0",
|
|
|
|
"https://*",
|
|
|
|
"https://localhost",
|
2022-01-11 11:46:28 +05:00
|
|
|
|
2021-12-22 15:59:02 +05:00
|
|
|
"https://0.0.0.0:3000",
|
|
|
|
"https://*:3000",
|
|
|
|
"https://localhost:3000",
|
2022-04-25 09:37:10 +05:00
|
|
|
|
2021-12-22 15:59:02 +05:00
|
|
|
"https://0.0.0.0:5001",
|
|
|
|
"https://*:5001",
|
2022-01-11 11:46:28 +05:00
|
|
|
"https://localhost:5001",
|
2022-04-22 17:26:03 +05:00
|
|
|
|
|
|
|
"https://0.0.0.0:443",
|
|
|
|
"https://*:443",
|
2022-04-25 09:37:10 +05:00
|
|
|
"https://localhost:443",
|
|
|
|
|
|
|
|
"http://cloud.autodrilling.ru",
|
2022-06-14 15:49:21 +05:00
|
|
|
"http://cloud.digitaldrilling.ru",
|
|
|
|
|
2022-07-05 10:40:32 +05:00
|
|
|
"https://cloud.autodrilling.ru",
|
|
|
|
"https://cloud.digitaldrilling.ru",
|
|
|
|
|
2022-06-14 15:49:21 +05:00
|
|
|
"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"
|
2021-05-20 14:30:25 +05:00
|
|
|
)
|
|
|
|
.AllowCredentials();
|
2021-04-08 17:54:02 +05:00
|
|
|
});
|
|
|
|
});
|
2022-01-05 17:50:45 +05:00
|
|
|
|
2023-03-30 12:57:32 +05:00
|
|
|
|
2021-04-02 17:28:07 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
|
|
{
|
|
|
|
app.UseSwagger();
|
|
|
|
app.UseSwaggerUI(c =>
|
|
|
|
{
|
2021-04-08 17:54:02 +05:00
|
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "V1");
|
2022-04-15 14:45:04 +05:00
|
|
|
c.EnablePersistAuthorization();
|
2022-06-16 17:37:10 +05:00
|
|
|
c.EnableFilter();
|
|
|
|
c.DisplayOperationId();
|
2021-04-02 17:28:07 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
//app.UseHttpsRedirection();
|
2021-06-09 17:21:44 +05:00
|
|
|
app.UseDefaultFiles();
|
2023-02-16 09:49:44 +05:00
|
|
|
app.UseStaticFiles(
|
|
|
|
//new StaticFileOptions
|
|
|
|
//{
|
|
|
|
// OnPrepareResponse = ctx =>
|
|
|
|
// {
|
|
|
|
// ctx.Context.Response.Headers.CacheControl = "public,max-age=2592000";
|
|
|
|
// ctx.Context.Response.Headers.Expires = DateTime.UtcNow.AddDays(10).ToString("R", CultureInfo.InvariantCulture);
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
);
|
2021-04-08 17:54:02 +05:00
|
|
|
app.UseCors("ClientPermission");
|
2021-04-02 17:28:07 +05:00
|
|
|
app.UseRouting();
|
2021-11-10 14:23:53 +05:00
|
|
|
|
|
|
|
app.UseResponseCaching();
|
|
|
|
//app.UseResponseCompression();
|
2022-04-11 18:00:34 +05:00
|
|
|
|
2021-04-02 17:28:07 +05:00
|
|
|
app.UseAuthentication();
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
2022-11-01 17:14:19 +05:00
|
|
|
app.UseMiddleware<PermissionsMiddlware>(Configuration);
|
2021-11-10 17:04:07 +05:00
|
|
|
app.UseMiddleware<SimplifyExceptionsMiddleware>();
|
|
|
|
app.UseMiddleware<RequerstTrackerMiddleware>();
|
2021-11-10 14:23:53 +05:00
|
|
|
|
2021-04-02 17:28:07 +05:00
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
{
|
|
|
|
endpoints.MapControllers();
|
2021-04-08 17:54:02 +05:00
|
|
|
endpoints.MapHub<TelemetryHub>("/hubs/telemetry");
|
2021-05-20 11:07:45 +05:00
|
|
|
endpoints.MapHub<ReportsHub>("/hubs/reports");
|
2021-04-02 17:28:07 +05:00
|
|
|
});
|
2021-07-05 09:36:27 +05:00
|
|
|
|
|
|
|
app.UseSpa(spa =>
|
|
|
|
{
|
|
|
|
spa.Options.SourcePath = "wwwroot";
|
|
|
|
});
|
2021-04-02 17:28:07 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|