diff --git a/src/BackOffice.BFF.WebApi/Program.cs b/src/BackOffice.BFF.WebApi/Program.cs index 4e3852f..9cb98b5 100644 --- a/src/BackOffice.BFF.WebApi/Program.cs +++ b/src/BackOffice.BFF.WebApi/Program.cs @@ -20,8 +20,8 @@ if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) var levelSwitch = new LoggingLevelSwitch(); var logger = new LoggerConfiguration() - .WriteTo.Seq("https://seq.afrino.co", - apiKey: "qPxY2VEQwMfWMI8IX4Fq", + .WriteTo.Seq(builder.Configuration["Seq:ServerUrl"] ?? "http://seq-svc:5341", + apiKey: string.IsNullOrEmpty(builder.Configuration["Seq:ApiKey"]) ? null : builder.Configuration["Seq:ApiKey"], controlLevelSwitch: levelSwitch) .CreateLogger(); builder.Logging.AddSerilog(logger); diff --git a/src/BackOffice.BFF.WebApi/Program.cs.bak b/src/BackOffice.BFF.WebApi/Program.cs.bak new file mode 100644 index 0000000..4e3852f --- /dev/null +++ b/src/BackOffice.BFF.WebApi/Program.cs.bak @@ -0,0 +1,99 @@ +using System.Reflection; +using System.Runtime.InteropServices; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Serilog; +using Serilog.Core; +using Microsoft.OpenApi.Models; + +var builder = WebApplication.CreateBuilder(args); +if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) +{ + builder.WebHost.ConfigureKestrel(options => + { + // Setup a HTTP/2 endpoint without TLS. + options.ListenLocalhost(5000, o => o.Protocols = + HttpProtocols.Http2); + }); +} + +var levelSwitch = new LoggingLevelSwitch(); +var logger = new LoggerConfiguration() + .WriteTo.Seq("https://seq.afrino.co", + apiKey: "qPxY2VEQwMfWMI8IX4Fq", + controlLevelSwitch: levelSwitch) + .CreateLogger(); +builder.Logging.AddSerilog(logger); +#if DEBUG +Serilog.Debugging.SelfLog.Enable(msg => Console.WriteLine(msg)); +#endif +// Additional configuration is required to successfully run gRPC on macOS. +// For instructions on how to configure Kestrel and gRPC clients on macOS, visit https://go.microsoft.com/fwlink/?linkid=2099682 + +// Add services to the container. +builder.Services.AddGrpc(options => +{ + options.EnableDetailedErrors = true; + options.MaxReceiveMessageSize = 1000 * 1024 * 1024; // 1 GB + options.MaxSendMessageSize = 1000 * 1024 * 1024; // 1 GB +}).AddJsonTranscoding(); +builder.Services.AddInfrastructureServices(builder.Configuration); +builder.Services.AddApplicationServices(); +builder.Services.AddPresentationServices(builder.Configuration); + +#region Configure Cors + +builder.Services.AddCors(options => +{ + options.AddPolicy("AllowAll", + builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().WithExposedHeaders("Grpc-Status", + "Grpc-Message", "Grpc-Encoding", "Grpc-Accept-Encoding", "validation-errors-text")); +}); + +#endregion +builder.Services.AddGrpcSwagger(); +builder.Services.AddSwaggerGen(c => +{ + c.SwaggerDoc("v1", new OpenApiInfo { Title = "gRPC transcoding", Version = "v1" }); + c.CustomSchemaIds(type=>type.ToString()); + c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme + { + In = ParameterLocation.Header, + Description = "Please insert JWT with Bearer into field", + Name = "Authorization", + Type = SecuritySchemeType.ApiKey + }); + c.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type = ReferenceType.SecurityScheme, + Id = "Bearer" + } + }, + new string[] { } + } + }); +}); +var app = builder.Build(); + +app.UseRouting(); +app.UseCors("AllowAll"); +app.UseAuthentication(); +app.UseAuthorization(); +app.UseGrpcWeb(new GrpcWebOptions { DefaultEnabled = true }); // Configure the HTTP request pipeline. +app.ConfigureGrpcEndpoints(Assembly.GetExecutingAssembly(), endpoints => +{ + // endpoints.MapGrpcService(); +}); +app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909"); +app.UseSwagger(); +app.UseSwaggerUI(c => +{ + c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); +}); +app.Run();