11using FaasNet . Runtime . Factories ;
2- using FaasNet . Runtime . Parameters ;
2+ using FaasNet . Runtime . GetSql . Middlewares ;
33using Microsoft . AspNetCore . Builder ;
44using Microsoft . AspNetCore . Http ;
5+ using Microsoft . Extensions . DependencyInjection ;
56using Newtonsoft . Json ;
6- using System ;
7+ using Prometheus ;
78using System . IO ;
8- using System . Net ;
9- using System . Threading . Tasks ;
109
1110namespace FaasNet . Runtime . GetSql
1211{
1312 public class Startup
1413 {
14+ public void ConfigureServices ( IServiceCollection services )
15+ {
16+ services . AddSingleton < MetricReporter > ( ) ;
17+ }
18+
1519 public void Configure ( IApplicationBuilder app )
1620 {
21+ app . UseMetricServer ( ) ;
1722 app . Map ( "/configuration" , ( c ) =>
1823 {
1924 c . Run ( async ( httpContext ) =>
@@ -25,38 +30,8 @@ public void Configure(IApplicationBuilder app)
2530 await httpContext . Response . WriteAsync ( json ) ;
2631 } ) ;
2732 } ) ;
28- app . Use ( async ( context , next ) =>
29- {
30- if ( context . Request . Method != HttpMethods . Post )
31- {
32- await next . Invoke ( ) ;
33- return ;
34- }
35-
36- var functionHandler = new FunctionHandler ( ) ;
37- try
38- {
39- var requestBody = await GetRequest ( context . Request . Body ) ;
40- var parameter = JsonConvert . DeserializeObject < FunctionParameter < GetSqlConfiguration > > ( requestBody ) ;
41- var result = await functionHandler . Handle ( parameter ) ;
42- context . Response . StatusCode = 200 ;
43- context . Response . ContentType = "application/json" ;
44- await context . Response . WriteAsync ( result . ToString ( ) ) ;
45- }
46- catch ( Exception ex )
47- {
48- context . Response . StatusCode = ( int ) HttpStatusCode . InternalServerError ;
49- await context . Response . WriteAsync ( ex . Message ) ;
50- }
51- } ) ;
52- }
53-
54- private Task < string > GetRequest ( Stream inputBody )
55- {
56- using ( var reader = new StreamReader ( inputBody ) )
57- {
58- return reader . ReadToEndAsync ( ) ;
59- }
33+ app . UseMiddleware < ResponseMetricMiddleware > ( ) ;
34+ app . UseMiddleware < FunctionMiddleware > ( ) ;
6035 }
6136 }
6237}
0 commit comments