2019-07-23 10:26:33 +02:00
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
2018-11-30 17:43:22 +01:00
|
|
|
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
2017-03-23 19:10:55 +01:00
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2018-11-30 17:43:22 +01:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2017-03-23 19:10:55 +01:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2019-01-03 17:11:56 +01:00
|
|
|
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
2017-03-23 19:10:55 +01:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
namespace WebStatus
|
|
|
|
|
{
|
|
|
|
|
public class Startup
|
|
|
|
|
{
|
2017-08-29 11:28:21 +02:00
|
|
|
|
public Startup(IConfiguration configuration)
|
2017-03-23 19:10:55 +01:00
|
|
|
|
{
|
2017-08-29 11:28:21 +02:00
|
|
|
|
Configuration = configuration;
|
2017-03-23 19:10:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-29 11:28:21 +02: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)
|
|
|
|
|
{
|
2017-10-13 11:35:26 +02:00
|
|
|
|
RegisterAppInsights(services);
|
2017-10-11 18:53:26 +02:00
|
|
|
|
|
2017-03-23 19:10:55 +01:00
|
|
|
|
services.AddOptions();
|
2019-01-03 17:11:56 +01:00
|
|
|
|
services.AddHealthChecks()
|
|
|
|
|
.AddCheck("self", () => HealthCheckResult.Healthy());
|
|
|
|
|
|
2018-11-30 17:43:22 +01:00
|
|
|
|
services.AddHealthChecksUI();
|
2019-07-23 10:26:33 +02:00
|
|
|
|
|
2018-11-14 16:21:50 +01:00
|
|
|
|
services.AddMvc()
|
2019-07-17 18:26:20 +02:00
|
|
|
|
.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);
|
2018-01-22 11:46:18 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-23 10:26:33 +02:00
|
|
|
|
app.UseHealthChecksUI(config =>
|
|
|
|
|
{
|
2019-01-03 17:11:56 +01:00
|
|
|
|
config.ResourcesPath = string.IsNullOrEmpty(pathBase) ? "/ui/resources" : $"{pathBase}/ui/resources";
|
2019-07-23 10:26:33 +02:00
|
|
|
|
config.UIPath = "/hc-ui";
|
2019-01-03 17:11:56 +01:00
|
|
|
|
});
|
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
|
|
|
|
});
|
|
|
|
|
}
|
2017-10-13 11:35:26 +02:00
|
|
|
|
|
|
|
|
|
private void RegisterAppInsights(IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
services.AddApplicationInsightsTelemetry(Configuration);
|
2019-07-23 12:14:09 +02:00
|
|
|
|
services.AddApplicationInsightsKubernetesEnricher();
|
2017-10-13 11:35:26 +02:00
|
|
|
|
}
|
2017-03-23 19:10:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|