public OpsEndpointsMiddleware(RequestDelegate next, OpsEndpointsMiddlewareOptions options) { _next = next; _handlers = ConfigureHandlers(options); _serializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; }
private Dictionary <string, HttpHandler> ConfigureHandlers(OpsEndpointsMiddlewareOptions options) { var ready = new HttpHandler(context => { var op = options; const string readyBody = "ready\n"; if (op.HealthModel.Ready()) { context.Response.StatusCode = 200; context.Response.ContentType = "text/plain"; return(context.Response.WriteAsync(readyBody)); } context.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable; return(Task.CompletedTask); }); var about = new HttpHandler(context => { var op = options; AboutResponse response = op.HealthModel.About().ToAboutResponse(); context.Response.StatusCode = 200; context.Response.ContentType = "application/json"; return(context.Response.WriteAsync(JsonConvert.SerializeObject(response, _serializerSettings))); }); var health = new HttpHandler(context => { var op = options; HealthResponse response = op.HealthModel.Health().ToHealthResponse(); context.Response.StatusCode = 200; context.Response.ContentType = "application/json"; return(context.Response.WriteAsync(JsonConvert.SerializeObject(response, _serializerSettings))); }); return(new Dictionary <string, HttpHandler> { { "/about", about }, { "/health", health }, { "/ready", ready } }); }
public static IApplicationBuilder UseOpsEndpoints(this IApplicationBuilder builder, OpsEndpointsMiddlewareOptions options) { return(builder.UseMiddleware <OpsEndpointsMiddleware>(options)); }