-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
65 lines (49 loc) · 1.83 KB
/
Program.cs
File metadata and controls
65 lines (49 loc) · 1.83 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
using FormagenAPI.Middlewares;
using FormagenAPI.Services;
using Models;
using Services;
var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
var builder = WebApplication.CreateBuilder(args);
string frontEndUrl = builder.Configuration.GetValue<string>("FrontEndUrl") ?? "https://localhost:3000";
// Add services to the container.
builder.Services.AddCors(options =>
{
options.AddPolicy(name: MyAllowSpecificOrigins,
policy =>
{
policy.WithOrigins(frontEndUrl)
.AllowCredentials()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
builder.Services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
builder.Services.Configure<DatabaseSettings>(
builder.Configuration.GetSection("FormStoreDatabase")
);
builder.Services.Configure<EmailServiceSettings>(
builder.Configuration.GetSection("EmailService")
);
builder.Services.AddSingleton<IUserService, UserService>();
builder.Services.AddSingleton<IAdminService, AdminService>();
builder.Services.AddSingleton<IFormService, FormService>();
builder.Services.AddSingleton<IEmailService, EmailService>();
builder.Services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.WriteIndented = true;
options.JsonSerializerOptions.AllowOutOfOrderMetadataProperties = true;
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.UseHttpsRedirection();
app.UseCors(MyAllowSpecificOrigins);
app.UseAuthorization();
app.MapControllers();
app.UseErrorHandling();
app.Run();