92 lines
3.5 KiB
C#
Raw Normal View History

2017-03-23 19:10:55 +01:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using WebStatus.Extensions;
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)
{
2017-10-11 16:26:44 +02:00
services.AddApplicationInsightsTelemetry(Configuration);
if (Configuration.GetValue<string>("OrchestratorType").Equals("K8S"))
{
// Enable K8s telemetry initializer
services.EnableKubernetes();
}
2017-03-23 19:10:55 +01:00
services.AddOptions();
2017-03-23 19:10:55 +01:00
// Add framework services.
services.AddHealthChecks(checks =>
{
var minutes = 1;
if (int.TryParse(Configuration["HealthCheck:Timeout"], out var minutesParsed))
{
minutes = minutesParsed;
}
checks.AddUrlCheckIfNotNull(Configuration["OrderingUrl"], TimeSpan.FromMinutes(minutes));
checks.AddUrlCheckIfNotNull(Configuration["BasketUrl"], TimeSpan.Zero); //No cache for this HealthCheck, better just for demos
checks.AddUrlCheckIfNotNull(Configuration["CatalogUrl"], TimeSpan.FromMinutes(minutes));
checks.AddUrlCheckIfNotNull(Configuration["IdentityUrl"], TimeSpan.FromMinutes(minutes));
checks.AddUrlCheckIfNotNull(Configuration["LocationsUrl"], TimeSpan.FromMinutes(minutes));
checks.AddUrlCheckIfNotNull(Configuration["MarketingUrl"], TimeSpan.FromMinutes(minutes));
checks.AddUrlCheckIfNotNull(Configuration["PaymentUrl"], TimeSpan.FromMinutes(minutes));
checks.AddUrlCheckIfNotNull(Configuration["mvc"], TimeSpan.Zero); //No cache for this HealthCheck, better just for demos
checks.AddUrlCheckIfNotNull(Configuration["spa"], TimeSpan.Zero); //No cache for this HealthCheck, better just for demos
2017-03-23 19:10:55 +01:00
});
2017-03-23 19:10:55 +01:00
services.AddMvc();
}
// 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();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
2017-09-07 19:18:53 +02:00
var pathBase = Configuration["PATH_BASE"];
if (!string.IsNullOrEmpty(pathBase))
{
app.UsePathBase(pathBase);
}
2017-03-23 19:10:55 +01:00
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}