// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IProblemFactory problemFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCors(builder => { builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .WithExposedHeaders("Location"); }); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); // unknown route app.Run(async context => { var problem = problemFactory.NotFound(); context.Response.ContentType = DefaultMediaTypes.ProblemJson; context.Response.StatusCode = problem.StatusCode; await context.Response.WriteAsync(JsonConvert.SerializeObject(problem)); }); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IProblemFactory problemFactory, IDriver driver, IHostApplicationLifetime hostApplicationLifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCors(builder => { builder .WithOrigins(new string[] { "http://localhost:8080", "https://mathiasreichardt.github.io", "https://hypermedia.marcel-weigel.de" }) //.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials() .WithExposedHeaders("Location"); } ); app.UseRouting(); app.UseDefaultFiles(); app.UseStaticFiles(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapHub <SensorHub>("/hub"); }); app.Run(async context => { var problem = problemFactory.NotFound(); context.Response.ContentType = DefaultMediaTypes.ProblemJson; context.Response.StatusCode = problem.StatusCode; await context.Response.WriteAsync(JsonConvert.SerializeObject(problem)); }); driver.Init(); hostApplicationLifetime.ApplicationStopping.Register(OnShutdown); }