// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Initializer initializer, ILogger <Startup> logger, LocalCache localCache, IOptions <ForgeConfiguration> forgeConfiguration)
        {
            if (Configuration.GetValue <bool>("clear"))
            {
                logger.LogInformation("-- Clean up --");
                // retrieve used Forge Client Id and Client Id where it is allowed to delete user buckets
                string clientIdCanDeleteUserBuckets = Configuration.GetValue <string>("clientIdCanDeleteUserBuckets");
                string clientId = forgeConfiguration.Value.ClientId;
                // only on allowed Client Id remove the user buckets
                bool deleteUserBuckets = (clientIdCanDeleteUserBuckets == clientId);
                initializer.ClearAsync(deleteUserBuckets).Wait();
            }

            if (Configuration.GetValue <bool>("initialize"))
            {
                logger.LogInformation("-- Initialization --");
                initializer.InitializeAsync().Wait();
            }

            if (Configuration.GetValue <bool>("bundles"))
            {
                logger.LogInformation("-- Initialization of AppBundles and Activities --");
                initializer.InitializeBundlesAsync().Wait();
            }

            if (env.IsDevelopment())
            {
                logger.LogInformation("In Development environment");
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            // expose local cache as static files
            localCache.Serve(app);

            app.UseSpaStaticFiles();
            app.UseMiddleware <HeaderTokenHandler>();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapHub <Controllers.JobsHub>("/signalr/connection");
            });

            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseReactDevelopmentServer(npmScript: "start");
                }
            });
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Initializer initializer,
                              ILogger <Startup> logger, LocalCache localCache, IOptions <ForgeConfiguration> forgeConfiguration,
                              Publisher publisher)
        {
            if (Configuration.GetValue <bool>("clear"))
            {
                logger.LogInformation("-- Clean up --");
                // retrieve used Forge Client Id and Client Id where it is allowed to delete user buckets
                string clientIdCanDeleteUserBuckets = Configuration.GetValue <string>("clientIdCanDeleteUserBuckets");
                string clientId = forgeConfiguration.Value.ClientId;
                // only on allowed Client Id remove the user buckets
                bool deleteUserBuckets = (clientIdCanDeleteUserBuckets == clientId);
                initializer.ClearAsync(deleteUserBuckets).Wait();
            }

            if (Configuration.GetValue <bool>("initialize"))
            {
                // force polling check for initializer, because callbacks
                // cannot be used at this point (no controllers are running yet)
                var oldCheckType = publisher.CompletionCheck;
                publisher.CompletionCheck = CompletionCheck.Polling;

                initializer.InitializeAsync().Wait();

                // reset configured value of completion check method
                publisher.CompletionCheck = oldCheckType;
            }

            if (Configuration.GetValue <bool>("bundles"))
            {
                logger.LogInformation("-- Initialization of AppBundles and Activities --");
                initializer.InitializeBundlesAsync().Wait();
            }

            if (env.IsDevelopment())
            {
                logger.LogInformation("In Development environment");
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            // expose local cache as static files
            localCache.Serve(app);

            app.UseSpaStaticFiles();

            // Use Serilog middleware to log ASP.NET requests. To not pollute logs with requests about
            // static file the middleware registered after middleware for serving static files.
            app.UseSerilogRequestLogging();

            app.UseMiddleware <HeaderTokenHandler>();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapHub <JobsHub>("/signalr/connection");
            });

            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseReactDevelopmentServer(npmScript: "start");
                }
            });
        }