// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.Run(async(context) => { var functionHandler = new FunctionHandler(); // Set up the MongoDB connection before calling the function handler. functionHandler.SetupConnection(); try { var requestBody = getRequest(context.Request.Body); var result = functionHandler.Handle(requestBody).Result; await context.Response.WriteAsync(result); } catch (Exception ex) { await context.Response.WriteAsync(ex.Message); } }); }