Beispiel #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseStatusCodePagesWithReExecute("/errors/{0}");

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(a =>
                {
                    a.Run(ctx =>
                    {
                        ctx.Response.StatusCode = StatusCodes.Status500InternalServerError;
                        return(Task.CompletedTask);
                    });
                });
            }

            using (StreamReader iisUrlRewriteStreamReader = File.OpenText("spa-url-rewrite.xml"))
            {
                RewriteOptions options = new RewriteOptions();
                options.AddRewrite(@"^assets/fonts/(.*)", "app/assets/fonts/$1", false);
                options.AddRewrite("^app$", "app/index.html", true);
                options.AddIISUrlRewrite(iisUrlRewriteStreamReader, true);

                app.UseRewriter(options);
            }

            app.UseStaticFiles(new StaticFileOptions()
            {
                OnPrepareResponse = ctx =>
                {
                    ctx.Context.Response.Headers.Append("Cache-Control", "public,max-age=3600");
                }
            });

            app.UseRouting();

            if (_authenticationEnabled)
            {
                app.UseAuthentication();
                app.UseAuthorization();
                app.UseMiddleware <SkillsCheckMiddleware>();
                app.UseMiddleware <LoggedInMiddleware>();
            }

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}");
                endpoints.MapHub <Notifications>("/api/notifications");
            });

            if (IsSwaggerEnabled())
            {
                app.UseSwagger();
                app.UseSwaggerUI(
                    options =>
                {
                    options.SwaggerEndpoint("/swagger/v1/swagger.json", "Calculations Funding Frontend API");
                    options.DocumentTitle = "Calculations Funding - Swagger";
                });
            }
        }