95 lines
3.3 KiB
C#
Raw Normal View History

using HealthChecks.UI.Client;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.ServiceFabric;
2017-03-23 19:10:55 +01: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.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.AddHealthChecksUI();
2018-11-14 16:21:50 +01:00
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
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
{
2017-10-11 16:26:44 +02:00
loggerFactory.AddAzureWebAppDiagnostics();
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
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);
}
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
app.Map("/liveness", lapp => lapp.Run(async ctx => ctx.Response.StatusCode = 200));
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
2017-09-07 19:18:53 +02:00
app.UseHealthChecksUI(config => config.UIPath = "/hc-ui");
2017-03-23 19:10:55 +01:00
app.UseStaticFiles();
2018-11-14 16:21:50 +01:00
app.UseHttpsRedirection();
2017-03-23 19:10:55 +01:00
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
private void RegisterAppInsights(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry(Configuration);
2017-10-16 16:10:40 +02:00
var orchestratorType = Configuration.GetValue<string>("OrchestratorType");
if (orchestratorType?.ToUpper() == "K8S")
{
// Enable K8s telemetry initializer
services.EnableKubernetes();
}
if (orchestratorType?.ToUpper() == "SF")
{
// Enable SF telemetry initializer
services.AddSingleton<ITelemetryInitializer>((serviceProvider) =>
new FabricTelemetryInitializer());
}
}
2017-03-23 19:10:55 +01:00
}
}