public MetricsModule() : base(MetricsModule.Config.ModulePath ?? "/") { if (string.IsNullOrEmpty(MetricsModule.Config.ModulePath)) { return; } MetricsModule.Config.ModuleConfigAction?.Invoke(this); Get("/", _ => { if (!this.Request.Url.Path.EndsWith("/")) { return(Response.AsRedirect(this.Request.Url.ToString() + "/")); } var gzip = AcceptsGzip(); var response = Response.FromStream(FlotWebApp.GetAppStream(!gzip), "text/html"); if (gzip) { response.WithHeader("Content-Encoding", "gzip"); } return(response); }); // Greedy Segment - /{name*} by adding a star/asterisk to the end of the segment name, // the pattern will match any value from the current forward slash onward. Get("/{path*}", p => { var path = (string)p.path; var endpointResponse = MetricsModule.Config.Handler.Process(path, this.Request); return(endpointResponse != null ? GetResponse(endpointResponse) : HttpStatusCode.NotFound); }); }
public MetricsModule() : base(Config.ModulePath ?? "/") { if (string.IsNullOrEmpty(Config.ModulePath)) { return; } Config.ModuleConfigAction?.Invoke(this); Get["/"] = _ => { if (!this.Request.Url.Path.EndsWith("/")) { return(Response.AsRedirect(this.Request.Url.ToString() + "/")); } var gzip = AcceptsGzip(); var response = Response.FromStream(FlotWebApp.GetAppStream(!gzip), "text/html"); if (gzip) { response.WithHeader("Content-Encoding", "gzip"); } return(response); }; Get["/{path*}"] = p => { var path = (string)p.path; var endpointResponse = Config.Handler.Process(path, this.Request); return(endpointResponse != null?GetResponse(endpointResponse) : HttpStatusCode.NotFound); }; }
public MetricsModule() : base(Config.ModulePath ?? "/") { if (string.IsNullOrEmpty(Config.ModulePath)) { return; } if (Config.ModuleConfigAction != null) { Config.ModuleConfigAction(this); } object[] noCacheHeaders = { new { Header = "Cache-Control", Value = "no-cache, no-store, must-revalidate" }, new { Header = "Pragma", Value = "no-cache" }, new { Header = "Expires", Value = "0" } }; Get["/"] = _ => { if (!this.Request.Url.Path.EndsWith("/")) { return(Response.AsRedirect(this.Request.Url.ToString() + "/")); } var gzip = AcceptsGzip(); var response = Response.FromStream(FlotWebApp.GetAppStream(!gzip), "text/html"); if (gzip) { response.WithHeader("Content-Encoding", "gzip"); } return(response); }; Get["/text"] = _ => Response.AsText(StringReport.RenderMetrics(Config.DataProvider.CurrentMetricsData, Config.HealthStatus)) .WithHeaders(noCacheHeaders); Get["/json"] = _ => Response.AsText(JsonBuilderV1.BuildJson(Config.DataProvider.CurrentMetricsData), "text/json") .WithHeaders(noCacheHeaders); Get["/v2/json"] = _ => Response.AsText(JsonBuilderV2.BuildJson(Config.DataProvider.CurrentMetricsData), "text/json") .WithHeaders(noCacheHeaders); Get["/ping"] = _ => Response.AsText("pong", "text/plain") .WithHeaders(noCacheHeaders); Get["/health"] = _ => GetHealthStatus() .WithHeaders(noCacheHeaders); }