From e5821ea6c805989852acf89c1765687171c1790f Mon Sep 17 00:00:00 2001 From: Rafsanul Hasan Date: Sat, 1 Sep 2018 17:39:21 +0600 Subject: [PATCH] Delete Startup.cs --- src/Web/WebSPA/Startup.cs | 160 -------------------------------------- 1 file changed, 160 deletions(-) delete mode 100644 src/Web/WebSPA/Startup.cs diff --git a/src/Web/WebSPA/Startup.cs b/src/Web/WebSPA/Startup.cs deleted file mode 100644 index c0c89f663..000000000 --- a/src/Web/WebSPA/Startup.cs +++ /dev/null @@ -1,160 +0,0 @@ -using eShopOnContainers.WebSPA; -using WebSPA.Infrastructure; - -namespace eShopConContainers.WebSPA -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - private readonly IHostingEnvironment _hostingEnv; - public Startup(IHostingEnvironment env) - { - _hostingEnv = env; - - var localPath = new Uri(Configuration["ASPNETCORE_URLS"])?.LocalPath ?? "/"; - Configuration["BaseUrl"] = localPath; - } - - // This method gets called by the runtime. Use this method to add services to the container. - // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 - public void ConfigureServices(IServiceCollection services) - { - RegisterAppInsights(services); - - services.AddHealthChecks(checks => - { - var minutes = 1; - if (int.TryParse(Configuration["HealthCheck:Timeout"], out var minutesParsed)) - { - minutes = minutesParsed; - } - - checks.AddUrlCheck(Configuration["CatalogUrlHC"], TimeSpan.FromMinutes(minutes)); - checks.AddUrlCheck(Configuration["OrderingUrlHC"], TimeSpan.FromMinutes(minutes)); - checks.AddUrlCheck(Configuration["BasketUrlHC"], TimeSpan.Zero); //No cache for this HealthCheck, better just for demos - checks.AddUrlCheck(Configuration["IdentityUrlHC"], TimeSpan.FromMinutes(minutes)); - checks.AddUrlCheck(Configuration["MarketingUrlHC"], TimeSpan.FromMinutes(minutes)); - - }); - - services.Configure(Configuration); - - if (Configuration.GetValue("IsClusterEnv") == bool.TrueString) - { - services.AddDataProtection(opts => - { - opts.ApplicationDiscriminator = "eshop.webspa"; - }) - .PersistKeysToRedis(ConnectionMultiplexer.Connect(Configuration["DPConnectionString"]), "DataProtection-Keys"); - } - - services.AddAntiforgery(options => options.HeaderName = "X-XSRF-TOKEN"); - - services - .AddMvc(opts => - { - opts.SslPort = 4104; - opts.RequireHttpsPermanent = true; - }) - .AddJsonOptions(options => - { - options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); - }); - - services.AddHttpsRedirection(opts => - { - opts.HttpsPort = 4104; - }); - } - - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IAntiforgery antiforgery) - { - - loggerFactory.AddAzureWebAppDiagnostics(); - loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); - - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - else - { - app.UseHsts(); - } - - app.UseHttpsRedirection(); - - // Configure XSRF middleware, This pattern is for SPA style applications where XSRF token is added on Index page - // load and passed back token on every subsequent async request - // app.Use(async (context, next) => - // { - // if (string.Equals(context.Request.Path.Value, "/", StringComparison.OrdinalIgnoreCase)) - // { - // var tokens = antiforgery.GetAndStoreTokens(context); - // context.Response.Cookies.Append("XSRF-TOKEN", tokens.RequestToken, new CookieOptions() { HttpOnly = false }); - // } - // await next.Invoke(); - // }); - - //Seed Data - WebContextSeed.Seed(app, env, loggerFactory); - - var pathBase = Configuration["PATH_BASE"]; - if (!string.IsNullOrEmpty(pathBase)) - { - loggerFactory.CreateLogger("init").LogDebug($"Using PATH BASE '{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 - - app.Use(async (context, next) => - { - await next(); - - // If there's no available file and the request doesn't contain an extension, we're probably trying to access a page. - // Rewrite request to use app root - if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value) && !context.Request.Path.Value.StartsWith("/api")) - { - context.Request.Path = "/index.html"; - context.Response.StatusCode = 200; // Make sure we update the status code, otherwise it returns 404 - await next(); - } - }); - - app.UseDefaultFiles(); - app.UseStaticFiles(); - - app.UseMvcWithDefaultRoute(); - } - - private void RegisterAppInsights(IServiceCollection services) - { - services.AddApplicationInsightsTelemetry(Configuration); - var orchestratorType = Configuration.GetValue("OrchestratorType"); - - if (orchestratorType?.ToUpper() == "K8S") - { - // Enable K8s telemetry initializer - services.EnableKubernetes(); - } - if (orchestratorType?.ToUpper() == "SF") - { - // Enable SF telemetry initializer - services.AddSingleton((serviceProvider) => - new FabricTelemetryInitializer()); - } - } - } -}