-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
48 lines (37 loc) · 1.05 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
using DotNetEnv;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddControllers();
builder.Services.AddOpenApi();
builder.Services.AddCors(options => {
options.AddPolicy(
"Production",
policy => policy
.WithOrigins("localhost")
.WithMethods(["GET", "OPTIONS", "PATCH", "DELETE", "POST"])
);
options.AddPolicy(
"Development",
policy => policy
.AllowAnyOrigin()
.WithMethods(["GET", "OPTIONS", "PATCH", "DELETE", "POST"])
);
});
builder.Configuration.AddEnvironmentVariables();
Env.Load();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
app.UseCors("Development");
}
else
{
app.UseCors("Production");
app.UseHttpsRedirection();
}
app.MapGet("/api/v1/health", () => "ok");
app.MapControllers();
app.Run();