-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
60 lines (50 loc) · 1.29 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using Api.Application.Startup;
using Microsoft.AspNetCore.Mvc;
using Serilog;
EnvManager.LoadConfig();
var AllowAnyOrigin = "_allowAnyOrigin";
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.SetupAppConfig();
await builder.Services.AddAppServices(builder.Configuration);
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration).CreateLogger();
builder.Host.UseSerilog();
builder.Services.AddCors(options =>
{
options.AddPolicy(name: AllowAnyOrigin,
policy =>
{
policy.SetIsOriginAllowed(origin => true)
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
});
});
builder.Services.Configure<ApiBehaviorOptions>(options =>
{
options.SuppressModelStateInvalidFilter = true;
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsProduction())
{
app.UseSwagger(c =>
{
c.RouteTemplate = "docs/{documentName}/openapi.yaml";
});
app.UseSwaggerUI(c =>
{
c.DocumentTitle = "My Api";
c.SwaggerEndpoint("/docs/v1/openapi.yaml", "My Api v1");
c.RoutePrefix = "docs";
});
}
app.UseCors(AllowAnyOrigin);
app.UseSerilogRequestLogging();
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseRateLimiter();
app.MapControllers();
app.Run();