using Bookstore.Data; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System.Threading.Tasks; namespace Bookstore.Web.Startup { public static class MiddlewareSetup { public static async Task ConfigureMiddlewareAsync(this WebApplication app) { app.Use((context, next) => { context.Request.Scheme = "https"; return next(context); }); if (app.Environment.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/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(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseSession(); app.MapAreaControllerRoute( name: "Admin", areaName: "Admin", pattern: "Admin/{controller=Orders}/{action=Index}/{id?}"); app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); // Create the database using (var scope = app.Services.CreateAsyncScope()) { await scope.ServiceProvider.GetService()!.Database.EnsureCreatedAsync(); } return app; } } }