예제 #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)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseServiceExceptionHandler();
            app.UseSwagger();
            app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "CitiesService v1"));

            app.UseApplicationLayer();

            //app.UseHttpsRedirection();
            app.UseRouting();

            app.UseAuthorization();

            app.UseCors("AllowAll");

            #region Healthchecks

            app.UseHealthChecks("/health", new HealthCheckOptions
            {
                ResponseWriter = async(context, report) =>
                {
                    context.Response.ContentType = "application/json";
                    var response = new HealthCheckReponse
                    {
                        Status = report.Status.ToString(),
                        HealthCheckDuration = report.TotalDuration,
                        HealthChecks        = report.Entries.Select(x => new IndividualHealthCheckResponse
                        {
                            Component   = x.Key,
                            Status      = x.Value.Status.ToString(),
                            Description = x.Value.Description
                        })
                    };
                    await context.Response.WriteAsync(JsonSerializer.Serialize(response));
                }
            });

            #endregion Healthchecks

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                //endpoints.MapHealthChecks("/health");
                endpoints.MapGet("/ping", ctx => ctx.Response.WriteAsync("pong"));
            });
        }
예제 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseHealthChecks("/healthchecks", new HealthCheckOptions
            {
                ResponseWriter = async(context, report) =>
                {
                    context.Response.ContentType = "application/json";
                    var response = new HealthCheckReponse
                    {
                        Status       = report.Status.ToString(),
                        HealthChecks = report.Entries.Select(x => new IndividualHealthCheckResponse
                        {
                            Component   = x.Key,
                            Status      = x.Value.Status.ToString(),
                            Description = x.Value.Description
                        }),
                        HealthCheckDuration = report.TotalDuration
                    };
                    await context.Response.WriteAsync(JsonConvert.SerializeObject(response));
                }
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });
        }
 public static void UseHealthChecks(this IApplicationBuilder app)
 {
     // app.UseHealthChecks("/health");
     app.UseHealthChecks("/health", new HealthCheckOptions
     {
         ResponseWriter = async(context, report) =>
         {
             context.Response.ContentType = "application/json";
             var response = new HealthCheckReponse
             {
                 Status       = report.Status.ToString(),
                 HealthChecks = report.Entries.Select(x => new IndividualHealthCheckResponse
                 {
                     Component   = x.Key,
                     Status      = x.Value.Status.ToString(),
                     Description = x.Value.Description
                 }),
                 HealthCheckDuration = report.TotalDuration
             };
             await context.Response.WriteAsync(JsonConvert.SerializeObject(response));
         }
     });
 }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseHealthChecks("/health", new HealthCheckOptions
            {
                ResponseWriter = async(context, report) =>
                {
                    context.Response.ContentType = "application/json";
                    var response = new HealthCheckReponse
                    {
                        Status       = report.Status.ToString(),
                        HealthChecks = report.Entries.Select(x => new IndividualHealthCheckResponse
                        {
                            Components  = x.Key,
                            Status      = x.Value.Status.ToString(),
                            Description = x.Value.Description
                        }),
                        HealthCheckDuration = report.TotalDuration
                    };
                    await context.Response.WriteAsync(JsonConvert.SerializeObject(response));
                }
            });
            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
예제 #5
0
        public static void UseSharedServices(this IApplicationBuilder app)
        {
            if (app == null)
            {
                return;
            }

            var loggerFactory = app.ApplicationServices.GetService(typeof(ILoggerFactory)) as ILoggerFactory;
            var config        = app.ApplicationServices.GetService(typeof(ISettings)) as ISettings;
            var logger        = loggerFactory.CreateLogger("Startup");
            var pathBase      = "";
            var environment   = app.ApplicationServices.GetService(typeof(IEnvironment)) as IEnvironment;

            if (environment.IsProduction)
            {
                if (!string.IsNullOrWhiteSpace(config.Meta.PathBase))
                {
                    logger.LogDebug("Setting base path to {0}", config.Meta.PathBase);
                    pathBase = config.Meta.PathBase;
                    app.UsePathBase(pathBase);
                }
                else
                {
                    logger.LogDebug("Skipping setting base path as no value was provided");
                }
            }
            else
            {
                logger.LogDebug("Skipping setting base path as no configuration parameter was found");
            }

            app.UseMiddleware <CorsMiddleware>();
            app.UseMiddleware <ExceptionMiddleware>();
            if (!environment.IsProduction)
            {
                var scheme = environment.IsDevelopment ? "http" : "https";
                app.UseSwagger(c =>
                {
                    c.RouteTemplate = "swagger/{documentName}/swagger.json";
                    c.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.Servers = new System.Collections.Generic.List <OpenApiServer>
                    {
                        new OpenApiServer {
                            Url = $"{scheme}://{httpReq.Host.Value}{pathBase}"
                        }
                    });
                });
                app.UseSwaggerUI(c => c.SwaggerEndpoint("v1/swagger.json", "API V1"));
            }

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints => endpoints.MapControllers());

            app.UseHealthChecks("/ready", new HealthCheckOptions
            {
                ResponseWriter = async(context, report) =>
                {
                    context.Response.ContentType = "application/json";
                    var response = new HealthCheckReponse
                    {
                        Status       = report.Status.ToString(),
                        HealthChecks = report.Entries.Select(x => new IndividualHealthCheckResponse
                        {
                            Component   = x.Key,
                            Status      = x.Value.Status.ToString(),
                            Description = x.Value.Description
                        }),
                        HealthCheckDuration = report.TotalDuration
                    };
                    await context.Response.WriteAsync(JsonConvert.SerializeObject(response)).ConfigureAwait(false);
                }
            });

            if (!string.IsNullOrWhiteSpace(config.Connection.MemcachedUrl))
            {
                app.UseEnyimMemcached();
            }
        }
예제 #6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApiVersionDescriptionProvider provider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            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.UseHealthChecks("/health", new HealthCheckOptions
            {
                ResponseWriter = async(context, report) =>
                {
                    context.Response.ContentType = "application/json";
                    var response = new HealthCheckReponse
                    {
                        Status       = report.Status.ToString(),
                        HealthChecks = report.Entries.Select(x => new IndividualHealthCheckResponse
                        {
                            Component   = x.Key,
                            Status      = x.Value.Status.ToString(),
                            Description = x.Value.Description
                        }),
                        HealthCheckDuration = report.TotalDuration
                    };
                    await context.Response.WriteAsync(JsonConvert.SerializeObject(response));
                }
            });

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

            app.UseRouting();
            app.UseSwagger();

            app.UseIdentityServer();
            app.UseAuthorization();

            app.UseSwaggerUI(c =>
            {
                c.OAuthClientId("mscoreone-swagger");
                c.OAuthClientSecret("secret");
                c.OAuthUsePkce();

                // build a swagger endpoint for each discorved API version
                foreach (var description in provider.ApiVersionDescriptions)
                {
                    c.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", description.GroupName.ToUpperInvariant());
                }
            });

            app.UseCors(MyAllowSpecificOrigins);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}");

                endpoints.MapRazorPages();
            });
        }