예제 #1
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IHealthService healthService)
        {
            app.Use(async(ctx, next) => {
                if (ctx.Request.Path == "/health")
                {
                    if (healthService.IsHealthy)
                    {
                        healthService.AddPing(true);
                        ctx.Response.StatusCode = 200;
                        await ctx.Response.WriteAsync("Healthy");
                        return;
                    }

                    healthService.AddPing(false);
                    ctx.Response.StatusCode = 500;
                    return;
                }
                await next();
            });

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }