86 lines
2.9 KiB
C#
Raw Normal View History

2019-07-23 10:26:33 +02:00
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
2017-03-23 19:10:55 +01:00
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
2017-03-23 19:10:55 +01:00
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
2017-03-23 19:10:55 +01:00
using Microsoft.Extensions.Logging;
namespace WebStatus
{
public class Startup
{
public Startup(IConfiguration configuration)
2017-03-23 19:10:55 +01:00
{
Configuration = configuration;
2017-03-23 19:10:55 +01:00
}
public IConfiguration Configuration { get; }
2017-03-23 19:10:55 +01:00
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
RegisterAppInsights(services);
2017-03-23 19:10:55 +01:00
services.AddOptions();
services.AddHealthChecks()
.AddCheck("self", () => HealthCheckResult.Healthy());
services.AddHealthChecksUI();
2019-07-23 10:26:33 +02:00
2018-11-14 16:21:50 +01:00
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
2017-03-23 19:10:55 +01:00
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
2017-10-11 16:26:44 +02:00
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
2017-03-23 19:10:55 +01:00
{
2019-02-18 16:53:29 +00:00
//loggerFactory.AddAzureWebAppDiagnostics();
//loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
2017-10-11 16:26:44 +02:00
2017-03-23 19:10:55 +01:00
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
2018-11-14 16:21:50 +01:00
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
2017-03-23 19:10:55 +01:00
}
2017-09-07 19:18:53 +02:00
var pathBase = Configuration["PATH_BASE"];
if (!string.IsNullOrEmpty(pathBase))
{
app.UsePathBase(pathBase);
}
2019-07-23 10:26:33 +02:00
app.UseHealthChecksUI(config =>
{
config.ResourcesPath = string.IsNullOrEmpty(pathBase) ? "/ui/resources" : $"{pathBase}/ui/resources";
2019-07-23 10:26:33 +02:00
config.UIPath = "/hc-ui";
});
2019-07-23 10:26:33 +02:00
2017-03-23 19:10:55 +01:00
app.UseStaticFiles();
2018-11-14 16:21:50 +01:00
app.UseHttpsRedirection();
2019-07-23 10:26:33 +02:00
app.UseEndpoints(endpoints =>
2017-03-23 19:10:55 +01:00
{
2019-07-23 10:26:33 +02:00
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
2019-07-23 12:14:09 +02:00
endpoints.MapHealthChecks("/liveness", new HealthCheckOptions
{
Predicate = r => r.Name.Contains("self")
});
2017-03-23 19:10:55 +01:00
});
}
private void RegisterAppInsights(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry(Configuration);
2019-07-23 12:14:09 +02:00
services.AddApplicationInsightsKubernetesEnricher();
}
2017-03-23 19:10:55 +01:00
}
}