Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing services to frontend project #24

Merged
merged 8 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ COPY ./src/${PROJECT_NAME}.Utils/${PROJECT_NAME}.Utils.csproj
COPY ./src/Tests/${PROJECT_NAME}.Api.Tests.Integration/${PROJECT_NAME}.Api.Tests.Integration.csproj ./src/Tests/${PROJECT_NAME}.Api.Tests.Integration/
COPY ./src/Tests/${PROJECT_NAME}.Application.Tests/${PROJECT_NAME}.Application.Tests.csproj ./src/Tests/${PROJECT_NAME}.Application.Tests/
COPY ./src/Tests/${PROJECT_NAME}.Domain.Tests/${PROJECT_NAME}.Domain.Tests.csproj ./src/Tests/${PROJECT_NAME}.Domain.Tests/
COPY ./src/Tests/${PROJECT_NAME}.Frontend.Tests/${PROJECT_NAME}.Frontend.Tests.csproj ./src/Tests/${PROJECT_NAME}.Frontend.Tests/
COPY ./src/Tests/${PROJECT_NAME}.Tests.Common/${PROJECT_NAME}.Tests.Common.csproj ./src/Tests/${PROJECT_NAME}.Tests.Common/

# Mount GitHub Token as a Docker secret so that NuGet Feed can be accessed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Identity.Web" Version="3.3.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ public static IServiceCollection AddInfrastructureDependencyGroup(
// Utils
services.AddScoped<IDateTimeProvider, DateTimeProvider>();

// Health check
AddInfrastructureHealthCheck(services);

return services;
}

public static void AddInfrastructureHealthCheck(this IServiceCollection services) {
services.AddHealthChecks()
.AddDbContextCheck<RegionalImprovementForStandardsAndExcellenceContext>("RISE Database");
}
}
}
31 changes: 25 additions & 6 deletions src/Dfe.RegionalImprovementForStandardsAndExcellence/Program.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@

using Microsoft.AspNetCore.CookiePolicy;

using Dfe.Academisation.CorrelationIdMiddleware;
using Dfe.RegionalImprovementForStandardsAndExcellence.Frontend.Models;
using Dfe.RegionalImprovementForStandardsAndExcellence.Frontend.Services;
using Dfe.RegionalImprovementForStandardsAndExcellence.Frontend.Services.AzureAd;
using Dfe.RegionalImprovementForStandardsAndExcellence.Frontend.Services.Http;
using Microsoft.Identity.Web;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Configuration;
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;

var builder = WebApplication.CreateBuilder(args);

Expand Down Expand Up @@ -74,11 +71,20 @@
options.Scope.Add("User.Read");
});

// Enforce HTTPS in ASP.NET Core
// @link https://learn.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?
builder.Services.AddHsts(options =>
{
options.Preload = true;
options.IncludeSubDomains = true;
options.MaxAge = TimeSpan.FromDays(365);
});

builder.Services.Configure<CookieAuthenticationOptions>(CookieAuthenticationDefaults.AuthenticationScheme,
options =>
{
options.AccessDeniedPath = "/access-denied";
options.Cookie.Name = ".Rise.Login";
options.Cookie.Name = ".RISE.Login";
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
options.ExpireTimeSpan = _authenticationExpiration;
Expand Down Expand Up @@ -118,12 +124,23 @@

var app = builder.Build();

var forwardOptions = new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.All,
RequireHeaderSymmetry = false
};
forwardOptions.KnownNetworks.Clear();
forwardOptions.KnownProxies.Clear();
app.UseForwardedHeaders(forwardOptions);

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
} else {
app.UseDeveloperExceptionPage();
}

app.UseHttpsRedirection();
Expand All @@ -146,6 +163,8 @@
endpoints.MapControllerRoute("default", "{controller}/{action}/");
});

app.UseHealthChecks("/health");

app.Run();

public partial class Program { } // Make the Program class partial for testing
public partial class Program { } // Make the Program class partial for testing
Loading