public static void UseEnvironmentEndpoint(this IApplicationBuilder app, bool includeEnvVars = true) { app.Use(async(context, next) => { if (context.Request.Path.Value.Equals("/env")) { // Perform IP access check if (MicroserviceConfiguration.AllowedIpAddresses != null && context.Request.HttpContext.Connection.RemoteIpAddress != null && !MicroserviceConfiguration.AllowedIpAddresses.Contains( context.Request.HttpContext.Connection.RemoteIpAddress)) { context.Response.StatusCode = 403; await next(); } // Get current application environment ApplicationEnvironment env = ApplicationEnvironment.GetApplicationEnvironment(includeEnvVars); context.Response.Headers["Content-Type"] = "application/json"; await context.Response.WriteAsync(JsonConvert.SerializeObject(env, Formatting.Indented, new JsonSerializerSettings() { StringEscapeHandling = StringEscapeHandling.EscapeNonAscii })); } else { await next(); } }); }
public static void UseEnvironmentEndpoint(this IAppBuilder app, bool includeEnvironmentVariables = false) { app.Use(async(context, next) => { if (context.Request.Path.Value.Equals("/env")) { // Get current application environment ApplicationEnvironment env = ApplicationEnvironment.GetApplicationEnvironment(includeEnvironmentVariables); context.Response.Headers.Set("Content-Type", "application/json"); await context.Response.WriteAsync(JsonConvert.SerializeObject(env, new JsonSerializerSettings() { StringEscapeHandling = StringEscapeHandling.EscapeNonAscii })); } else { await next(); } }); }