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;
|
2017-10-13 11:35:26 +02:00
|
|
|
|
using Microsoft.ApplicationInsights.Extensibility;
|
|
|
|
|
using Microsoft.ApplicationInsights.ServiceFabric;
|
2017-03-23 19:10:55 +01:00
|
|
|
|
|
|
|
|
|
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();
|
2017-08-29 11:28:21 +02:00
|
|
|
|
|
2017-03-23 19:10:55 +01:00
|
|
|
|
// Add framework services.
|
|
|
|
|
services.AddHealthChecks(checks =>
|
|
|
|
|
{
|
2017-05-09 13:54:45 +02:00
|
|
|
|
var minutes = 1;
|
|
|
|
|
if (int.TryParse(Configuration["HealthCheck:Timeout"], out var minutesParsed))
|
|
|
|
|
{
|
|
|
|
|
minutes = minutesParsed;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-25 14:45:53 -04:00
|
|
|
|
checks.AddUrlCheckIfNotNull(Configuration["OrderingUrl"], TimeSpan.FromMinutes(minutes));
|
2017-07-13 14:48:55 -07:00
|
|
|
|
checks.AddUrlCheckIfNotNull(Configuration["BasketUrl"], TimeSpan.Zero); //No cache for this HealthCheck, better just for demos
|
2017-09-25 14:45:53 -04:00
|
|
|
|
checks.AddUrlCheckIfNotNull(Configuration["CatalogUrl"], TimeSpan.FromMinutes(minutes));
|
|
|
|
|
checks.AddUrlCheckIfNotNull(Configuration["IdentityUrl"], TimeSpan.FromMinutes(minutes));
|
2017-07-04 11:27:16 +02:00
|
|
|
|
checks.AddUrlCheckIfNotNull(Configuration["LocationsUrl"], TimeSpan.FromMinutes(minutes));
|
2017-09-25 14:45:53 -04:00
|
|
|
|
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-08-29 11:28:21 +02: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?}");
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-10-13 11:35:26 +02:00
|
|
|
|
|
|
|
|
|
private void RegisterAppInsights(IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
services.AddApplicationInsightsTelemetry(Configuration);
|
|
|
|
|
|
|
|
|
|
if (Configuration.GetValue<string>("OrchestratorType").Equals("K8S"))
|
|
|
|
|
{
|
|
|
|
|
// Enable K8s telemetry initializer
|
|
|
|
|
services.EnableKubernetes();
|
|
|
|
|
}
|
|
|
|
|
if (Configuration.GetValue<string>("OrchestratorType").Equals("SF"))
|
|
|
|
|
{
|
|
|
|
|
// Enable SF telemetry initializer
|
|
|
|
|
services.AddSingleton<ITelemetryInitializer>((serviceProvider) =>
|
|
|
|
|
new FabricTelemetryInitializer());
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-23 19:10:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|