-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
74 lines (54 loc) · 1.91 KB
/
Program.cs
File metadata and controls
74 lines (54 loc) · 1.91 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
using Microsoft.OpenApi.Models;
using NoFlowEngine.Middlewares;
using NoFlowEngine.Extensions;
using NoFlowEngine.Exceptions;
using NoFlowEngine.Helpers;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("Configuration/appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"Configuration/appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
builder.Services.AddControllersWithViews();
var connectionString = builder.Configuration.GetDefaultConnectionString();
builder.Services.ConfigureDatabase(connectionString);
builder.Services.ConfigureServices();
builder.Services.AddHttpContextAccessor();
// Swagger configuration
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "NoFlowEngine API", Version = "v1" });
});
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "NoFlowEngine API V1");
});
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
DatabaseInitializer.InitializeDatabase(app);
var logger = app.Services.GetRequiredService<ILogger<Program>>();
app.ConfigureExceptionHandler(logger);
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseRequestResponseLogging();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapControllerRoute(
name: "api",
pattern: "api/{controller}/{action}/{id?}");
app.Run();