-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
93 lines (68 loc) · 2.31 KB
/
Program.cs
File metadata and controls
93 lines (68 loc) · 2.31 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using Microsoft.EntityFrameworkCore;
using PartyFunApi.Data;
using PartyFunApi.Extensions;
using PartyFunApi.Helpers;
using PartyFunApi.Middlewares;
using PartyFunApi.Routes;
// Load .env on development
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
{
var root = Directory.GetCurrentDirectory();
var dotenv = Path.Combine(root, ".env");
Dotenv.Load(dotenv);
}
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddControllers();
builder.Services.AddApplicationService(builder.Configuration);
builder.Services.AddDatabaseService(builder.Configuration);
var app = builder.Build();
// auto apply migration on service start
using var scope = app.Services.CreateScope();
var services = scope.ServiceProvider;
try
{
var context = services.GetRequiredService<DataContext>();
await context.Database.MigrateAsync();
}
catch (Exception ex)
{
var logger = services.GetService<ILogger<Program>>();
logger?.LogError(ex, "An error occured during migration");
}
// Configure the HTTP request pipeline.
// if (app.Environment.IsDevelopment())
// {
// app.UseSwagger();
// app.UseSwaggerUI();
// }
// app.MapGet("/", ([FromHeader] HttpContext context, [FromServices] IAntiforgery antiforgery) =>
// {
// var token = antiforgery.GetAndStoreTokens(context);
// if (token?.HeaderName != null && token?.RequestToken != null)
// {
// context.Response.Cookies.Append("X-XSRF-TOKEN", token.RequestToken, new CookieOptions { HttpOnly = false });
// }
// Console.WriteLine("tokenHeaderName {0}, tokenHeaderCookier {1}, tokenHeaderRequestToken {2}", token.HeaderName, token.CookieToken, token.RequestToken);
// return Results.NoContent();
// });
app.MapUserRoute();
app.MapProductRoute();
app.MapSalesRoute();
// app.MapProductRoute();
app.UseSwagger();
app.UseSwaggerUI();
app.UseCors(builder =>
builder.AllowAnyHeader()
.AllowAnyMethod()
.WithOrigins("http://localhost:4200", "https://*.vercel.app", "https://*.jointheirsassesmbly.org")
.AllowCredentials()
.AllowAnyHeader()
);
app.UseMiddleware<ExceptionMiddlewares>();
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();