|
3 | 3 | using Microsoft.AspNetCore.DataProtection; |
4 | 4 | using Microsoft.AspNetCore.HttpOverrides; |
5 | 5 | using Microsoft.AspNetCore.Mvc.ApplicationModels; |
| 6 | +using Microsoft.AspNetCore.ResponseCompression; |
| 7 | +using Microsoft.AspNetCore.Server.Kestrel.Core; |
6 | 8 | using Microsoft.EntityFrameworkCore; |
7 | 9 | using Website.Common; |
8 | 10 | using Website.Services; |
|
28 | 30 | services.AddDbContext<DatabaseContext>(options => |
29 | 31 | options.UseSqlite(config.GetConnectionString("WebsiteDatabase"))); |
30 | 32 |
|
| 33 | +// Compression |
| 34 | +services.AddResponseCompression(options => |
| 35 | +{ |
| 36 | + options.Providers.Add<BrotliCompressionProvider>(); |
| 37 | + options.Providers.Add<GzipCompressionProvider>(); |
| 38 | +}); |
| 39 | + |
31 | 40 | // Razor pages (most pages on this site) |
32 | | -services.AddRazorPages(options => |
| 41 | +var razorBuilder = services.AddRazorPages(options => |
33 | 42 | { |
| 43 | + options.Conventions.Add(new PageRouteTransformerConvention(new SlugifyParameterTransformer())); |
| 44 | + |
34 | 45 | options.Conventions.AuthorizePage("/Admin"); |
35 | 46 | }); |
36 | 47 |
|
37 | 48 | // Allows us to use controllers alongside razor pages |
38 | | -services.AddMvc(); |
| 49 | +var mvcBuilder = services.AddMvc(); |
| 50 | + |
| 51 | +// Allows compiling within development environment |
| 52 | +if (environment.IsDevelopment()) |
| 53 | +{ |
| 54 | + razorBuilder.AddRazorRuntimeCompilation(); |
| 55 | + mvcBuilder.AddRazorRuntimeCompilation(); |
| 56 | +} |
39 | 57 |
|
40 | 58 | // Bundle and minify our JS and CSS |
41 | 59 | services.AddWebOptimizer(pipeline => |
|
73 | 91 | services.AddSingleton<SoundByteAuthenticationService>(); |
74 | 92 | services.AddSingleton<R2>(); |
75 | 93 |
|
76 | | -var mvcBuilder = services.AddRazorPages(options => |
77 | | - options.Conventions.Add(new PageRouteTransformerConvention(new SlugifyParameterTransformer()))); |
78 | | - |
79 | | -if (environment.IsDevelopment()) |
80 | | -{ |
81 | | - mvcBuilder.AddRazorRuntimeCompilation(); |
82 | | -} |
83 | | - |
84 | 94 | // ----- App ----- // |
85 | 95 |
|
86 | 96 | var app = builder.Build(); |
|
128 | 138 | app.UseAuthentication(); |
129 | 139 | app.UseAuthorization(); |
130 | 140 |
|
| 141 | +app.UseResponseCompression(); |
| 142 | + |
131 | 143 | app.MapHtmxAntiforgeryScript(); |
132 | 144 |
|
133 | 145 | app.MapRazorPages(); |
|
0 commit comments