-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
88 lines (62 loc) · 1.99 KB
/
Program.cs
File metadata and controls
88 lines (62 loc) · 1.99 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
using FileForge.Data;
using FileForge.Entities.Base;
using Microsoft.EntityFrameworkCore;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using FileForge.Extensions;
var builder = WebApplication.CreateBuilder(args);
// services
builder.Services.AddHttpContextAccessor();
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll", policy =>
{
policy.SetIsOriginAllowed(_ => true)
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();
});
});
builder.Services.AddBusinessServices();
//builder.Services.AddValidationConfigurations();
builder.Services.AddControllers().AddJsonOptions(options => {
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
});
builder.Services.AddOpenApi();
// EF Core DB Connection
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
// Swagger
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Seed Database
//using (var scope = app.Services.CreateScope())
//{
// var services = scope.ServiceProvider;
// await DatabaseSeeder.SeedAsync(services);
//}
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
// Swagger
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseCors("AllowAll");
app.UseAuthentication();
app.UseAuthorization();
app.UseHttpsRedirection();
app.MapControllers();
app.UseDefaultFiles();
app.UseStaticFiles();
app.MapGet("/api", () => Results.Ok(ApiResponse<string>.Ok("Hello, Welcome to CMS API")));
app.MapPost("/check-data", async (HttpContext context) =>
{
using var reader = new StreamReader(context.Request.Body);
var body = await reader.ReadToEndAsync();
var jsonBody = JsonDocument.Parse(body).RootElement;
return Results.Created("/api", ApiResponse<JsonElement>.Ok("Data received successfully", jsonBody));
});
app.Run();