Skip to content

Commit

Permalink
Update old NPM packages
Browse files Browse the repository at this point in the history
Remove aspnet webpack to make way for .NET 5 upgrade, and hot module
reloading of the site, which is much more difficult in .NET 5. See
this issue for a discussion of the .NET changes that lead to this
dotnet/aspnetcore#12890

Update webpack from verion 4 to 5. This required changing how GOV.UK
assets are made accessible, they are now included using the CopyPlugin.
  • Loading branch information
benjimarshall committed Feb 17, 2021
1 parent 4d5bd9a commit a65eff6
Show file tree
Hide file tree
Showing 8 changed files with 2,222 additions and 6,073 deletions.
45 changes: 22 additions & 23 deletions ntbs-service/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -57,8 +56,8 @@ public Startup(IConfiguration configuration, IHostingEnvironment env)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// This was helpful for identifying issues with ADFS login - but shouldn't be on usually
// IdentityModelEventSource.ShowPII = true;
// This was helpful for identifying issues with ADFS login - but shouldn't be on usually
// IdentityModelEventSource.ShowPII = true;
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = ForwardedHeaders.All;
Expand Down Expand Up @@ -109,7 +108,7 @@ public void ConfigureServices(IServiceCollection services)

Log.Information($"Basic Auth Enabled: {basicAuthEnabled}");
Log.Information($"Azure Ad Auth Enabled: {azureAdAuthEnabled}");

var baseUserGroupRole = adfsConfig["BaseUserGroup"];


Expand All @@ -121,8 +120,8 @@ public void ConfigureServices(IServiceCollection services)
}
else
UseAdfsAuthentication(services, adfsConfig);



services.AddMvc(options =>
{
Expand Down Expand Up @@ -153,15 +152,15 @@ public void ConfigureServices(IServiceCollection services)
services.AddDbContext<NtbsContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("ntbsContext"))
);

services.AddSingleton<NtbsContextDesignTimeFactory>();

var auditDbConnectionString = Configuration.GetConnectionString("auditContext");

services.AddDbContext<AuditDatabaseContext>(options =>
options.UseSqlServer(auditDbConnectionString)
);

// Add a DbContext for Data Protection key storage
services.AddDbContext<KeysContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("keysContext")));
Expand Down Expand Up @@ -286,7 +285,7 @@ private static void UseAdfsAuthentication(IServiceCollection services, IConfigur
};
})
.AddCookie(options => { options.ForwardAuthenticate = setupDummyAuth ? DummyAuthHandler.Name : null; });


if (setupDummyAuth)
{
Expand All @@ -312,9 +311,9 @@ private void UseAzureAdAuthentication(IServiceCollection services, IConfiguratio
options.CallbackPath = azureAdConfig["CallbackPath"];
options.CorrelationCookie.SameSite = SameSiteMode.None;
options.CorrelationCookie.SecurePolicy = CookieSecurePolicy.Always;
options.Events = new OpenIdConnectEvents();
options.Events.OnTokenValidated += async context =>
options.Events.OnTokenValidated += async context =>
{
var username = context.Principal.Username();
if (username == null) {
Expand Down Expand Up @@ -396,7 +395,7 @@ private static void UseHttpBasicAuth(IServiceCollection services,
context.UserName,
context.Options.ClaimsIssuer),
new Claim(ClaimTypes.Role, adfsOptions.BaseUserGroup, ClaimValueTypes.String),
new Claim(ClaimTypes.Role, groupAdmin, ClaimValueTypes.String),
new Claim(ClaimTypes.Role, groupDev, ClaimValueTypes.String)
};
Expand Down Expand Up @@ -440,11 +439,11 @@ private void AddAdImportService(IServiceCollection services)
{
services.AddScoped<IAdImportService, AzureAdImportService>();
}
else
else
{
services.AddScoped<IAdImportService, AdImportService>();
}

}

private void AddClusterService(IServiceCollection services)
Expand Down Expand Up @@ -515,16 +514,16 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseForwardedHeaders();
app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true, ConfigFile = "webpack.dev.js"
});

// Hot module reloading has been made more difficult in .NET 5 because UseWebpackDevMiddleware was removed
// See https://github.com/dotnet/AspNetCore/issues/12890 for discussion of this change

// We only need to turn this on in development, as in production this
// This behaviour is by default provided by the nginx ingress
// (see https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#server-side-https-enforcement-through-redirect)
// (also see HSTS setting below)
app.UseHttpsRedirection();

}
else
{
Expand All @@ -551,22 +550,22 @@ Making this conditional is the result of serilog not playing nicely with WebAppl
// 400s get thrown e.g. on antiforgery token validation failures. In those cases we don't have
// an exception logged in Sentry, so we want to log at Warning level to make sure we are able to
// identify and cure false positives.
// Otherwise setting to Information to prevent duplicated exceptions in sentry.
// Otherwise setting to Information to prevent duplicated exceptions in sentry.
options.GetLevel = (context, _, __) => context.Response.StatusCode == StatusCodes.Status400BadRequest
? LogEventLevel.Warning
? LogEventLevel.Warning
: LogEventLevel.Information;
});
}

app.UseAuthentication();
app.UseCookiePolicy();
app.UseSession();

if (!Env.IsEnvironment("CI"))
{
app.UseMiddleware<ActivityDetectionMiddleware>();
}

if (Configuration.GetValue<bool>(Constants.AuditEnabledConfigValue))
{
app.UseMiddleware<AuditGetRequestMiddleWare>();
Expand Down
Loading

0 comments on commit a65eff6

Please sign in to comment.