| | | 1 | | using Syki.Back.Hubs; |
| | | 2 | | using Syki.Back.Converters; |
| | | 3 | | |
| | | 4 | | namespace Syki.Back.Configs; |
| | | 5 | | |
| | | 6 | | public static class HttpConfigs |
| | | 7 | | { |
| | | 8 | | public static void AddHttpConfigs(this WebApplicationBuilder builder) |
| | | 9 | | { |
| | 2 | 10 | | builder.Services.AddControllers().AddJsonOptions(options => |
| | 4 | 11 | | options.JsonSerializerOptions.Converters.Add(new SykiStringEnumConverter())); |
| | | 12 | | |
| | 2 | 13 | | builder.Services.Configure<MvcOptions>(options => |
| | 2 | 14 | | { |
| | 2 | 15 | | options.Filters.Add(new ProducesAttribute("application/json")); |
| | 2 | 16 | | options.Filters.Add(new ConsumesAttribute("application/json")); |
| | 4 | 17 | | }); |
| | | 18 | | |
| | 2 | 19 | | builder.Services.AddHttpContextAccessor(); |
| | 4 | 20 | | builder.Services.AddRouting(options => options.LowercaseUrls = true); |
| | | 21 | | |
| | 2 | 22 | | builder.Services.AddSignalR(); |
| | | 23 | | |
| | 2 | 24 | | builder.Services.AddHttpClient(); |
| | 2 | 25 | | } |
| | | 26 | | |
| | | 27 | | public static void UseExceptions(this IApplicationBuilder app) |
| | | 28 | | { |
| | 2 | 29 | | app.UseMiddleware<ExceptionsMiddleware>(); |
| | 2 | 30 | | } |
| | | 31 | | |
| | | 32 | | public static void UseCustomHeaders(this IApplicationBuilder app) |
| | | 33 | | { |
| | 2 | 34 | | app.UseMiddleware<CustomHeadersMiddleware>(); |
| | 2 | 35 | | } |
| | | 36 | | |
| | | 37 | | public static void UseControllers(this IApplicationBuilder app) |
| | | 38 | | { |
| | 2 | 39 | | app.UseEndpoints(options => |
| | 2 | 40 | | { |
| | 2 | 41 | | options.MapControllers(); |
| | 2 | 42 | | |
| | 2 | 43 | | options.MapHub<SykiHub>("/syki-hub"); |
| | 2 | 44 | | |
| | 2 | 45 | | options.MapOpenApi(); |
| | 2 | 46 | | options.MapScalarDocs(); |
| | 4 | 47 | | }); |
| | 2 | 48 | | } |
| | | 49 | | |
| | | 50 | | public static void UseLogs(this IApplicationBuilder app) |
| | | 51 | | { |
| | 2 | 52 | | app.UseSerilogRequestLogging(); |
| | 2 | 53 | | } |
| | | 54 | | } |