forked from ddrilling/AsbCloudServer
157 lines
5.4 KiB
C#
157 lines
5.4 KiB
C#
using AsbCloudInfrastructure;
|
|
using AsbCloudWebApi.Converters;
|
|
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;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
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<JsonOptions>(options =>
|
|
{
|
|
options.JsonSerializerOptions.NumberHandling =
|
|
System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals |
|
|
System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString;
|
|
|
|
options.JsonSerializerOptions.Converters.Add(new DateOnlyJsonConverter());
|
|
options.JsonSerializerOptions.Converters.Add(new JsonValueJsonConverter());
|
|
}))
|
|
.AddProtoBufNet();
|
|
|
|
services.AddControllers(options => options.UseDateOnlyTimeOnlyStringConverters());
|
|
|
|
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",
|
|
"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();
|
|
});
|
|
});
|
|
|
|
|
|
}
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI(c =>
|
|
{
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "V1");
|
|
c.EnablePersistAuthorization();
|
|
c.EnableFilter();
|
|
c.DisplayOperationId();
|
|
});
|
|
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
|
|
//app.UseHttpsRedirection();
|
|
app.UseDefaultFiles();
|
|
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);
|
|
// }
|
|
//}
|
|
);
|
|
app.UseCors("ClientPermission");
|
|
app.UseRouting();
|
|
|
|
app.UseResponseCaching();
|
|
//app.UseResponseCompression();
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.UseMiddleware<PermissionsMiddlware>(Configuration);
|
|
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";
|
|
});
|
|
}
|
|
}
|
|
}
|