// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseDeveloperExceptionPage(); app.UseExceptionHandlerMiddleware(); app.UseStaticFiles(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "SHAREBOOK API V1"); }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Book}/{action=Index}/{id?}"); routes.MapSpaFallbackRoute( name: "spa-fallback", defaults: new { controller = "ClientSpa", action = "Index" }); }); using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var scopeServiceProvider = serviceScope.ServiceProvider; var context = serviceScope.ServiceProvider.GetService <ApplicationDbContext>(); context.Database.Migrate(); var sharebookSeeder = new ShareBookSeeder(context); sharebookSeeder.Seed(); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseExceptionHandlerMiddleware(); } app.UseMvc(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "SHAREBOOK API V1"); }); using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var scopeServiceProvider = serviceScope.ServiceProvider; var context = serviceScope.ServiceProvider.GetService <ApplicationDbContext>(); context.Database.Migrate(); var sharebookSeeder = new ShareBookSeeder(context); sharebookSeeder.Seed(); } }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { bool rollbarActive = Configuration.GetSection("Rollbar:IsActive").Value == null ? false : Convert.ToBoolean(Configuration.GetSection("Rollbar:IsActive").Value.ToLower()); if (rollbarActive) { app.UseRollbarMiddleware(); } app.UseHealthChecks("/hc"); app.UseExceptionHandlerMiddleware(); app.UseStaticFiles(new StaticFileOptions() { OnPrepareResponse = (context) => { // Enable cors context.Context.Response.Headers["Access-Control-Allow-Origin"] = "*"; } }); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "SHAREBOOK API V1"); }); app.UseRouting(); app.UseCors("AllowAllHeaders"); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Book}/{action=Index}/{id?}"); endpoints.MapFallbackToController("Index", "ClientSpa"); endpoints.MapHealthChecks("/health", new HealthCheckOptions() { AllowCachingResponses = false, ResultStatusCodes = { [HealthStatus.Healthy] = StatusCodes.Status200OK, [HealthStatus.Degraded] = StatusCodes.Status200OK, [HealthStatus.Unhealthy] = StatusCodes.Status503ServiceUnavailable } }); }); using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var scopeServiceProvider = serviceScope.ServiceProvider; var context = serviceScope.ServiceProvider.GetService <ApplicationDbContext>(); context.Database.Migrate(); if (env.IsDevelopment() || env.IsStaging()) { var sharebookSeeder = new ShareBookSeeder(context); sharebookSeeder.Seed(); } } }