-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgram.cs
107 lines (84 loc) · 3.2 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using Dfe.PlanTech.Application.Constants;
using Dfe.PlanTech.Application.Helpers;
using Dfe.PlanTech.Domain.Content.Interfaces;
using Dfe.PlanTech.Domain.Helpers;
using Dfe.PlanTech.Domain.Interfaces;
using Dfe.PlanTech.Infrastructure.ServiceBus;
using Dfe.PlanTech.Infrastructure.SignIns;
using Dfe.PlanTech.Web;
using Dfe.PlanTech.Web.Configuration;
using Dfe.PlanTech.Web.Middleware;
using Dfe.PlanTech.Web.Models;
using GovUk.Frontend.AspNetCore;
using Microsoft.Extensions.Options;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddResponseCompression(options =>
{
options.EnableForHttps = true;
});
builder.Services.AddControllersWithViews();
if (!builder.Environment.IsDevelopment())
{
builder.Services.AddReleaseServices(builder.Configuration);
}
if (builder.Environment.EnvironmentName != "E2E")
{
builder.Services.AddDbWriterServices(builder.Configuration);
}
builder.Services.AddCustomTelemetry();
builder.Services.Configure<ErrorMessages>(builder.Configuration.GetSection("ErrorMessages"));
builder.Services.Configure<ErrorPages>(builder.Configuration.GetSection("ErrorPages"));
builder.Services.Configure<ContactOptions>(builder.Configuration.GetSection("ContactUs"));
builder.AddContentAndSupportServices()
.AddAuthorisationServices()
.AddCaching()
.AddContentfulServices(builder.Configuration)
.AddCQRSServices()
.AddCspConfiguration()
.AddDatabase(builder.Configuration)
.AddDfeSignIn(builder.Configuration)
.AddExceptionHandlingServices()
.AddGoogleTagManager()
.AddGovUkFrontend()
.AddHttpContextAccessor()
.AddRoutingServices()
.AddRedisServices(builder.Configuration);
builder.Services.AddSingleton<ISystemTime, SystemTime>();
builder.Services.Configure<RobotsConfiguration>(builder.Configuration.GetSection("Robots"));
var app = builder.Build();
app.UseRobotsTxtMiddleware();
app.UseSecurityHeaders();
app.UseMiddleware<HeadRequestMiddleware>();
app.UseCookiePolicy(
new CookiePolicyOptions
{
Secure = CookieSecurePolicy.Always
});
app.UseForwardedHeaders();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseExceptionHandler(exceptionHandlerApp =>
{
exceptionHandlerApp.Run(async context =>
{
var exceptionHandlerMiddleware = context.RequestServices.GetRequiredService<IExceptionHandlerMiddleware>();
var pageQuery = context.RequestServices.GetRequiredService<IGetPageQuery>();
var errorPages = context.RequestServices.GetRequiredService<IOptions<ErrorPages>>();
var internalErrorPage = await pageQuery.GetPageById(errorPages.Value.InternalErrorPageId);
var internalErrorSlug = internalErrorPage?.Slug ?? UrlConstants.Error;
exceptionHandlerMiddleware.ContextRedirect(internalErrorSlug, context);
});
});
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllerRoute(
pattern: "{controller=Pages}/{action=GetByRoute}/{id?}",
name: "default"
);
await app.RunAsync();