|
20 | 20 | builder.Services.AddControllers(); |
21 | 21 | builder.Services.AddEndpointsApiExplorer(); |
22 | 22 | builder.Services.AddSwaggerGen(); |
| 23 | +builder.Services.AddHttpClient(); |
23 | 24 |
|
24 | 25 | // 3. CONFIGURAÇÃO JWT |
25 | 26 | var jwtSettingsSection = builder.Configuration.GetSection("GatewaySettings"); |
|
78 | 79 | app.UseSwagger(); |
79 | 80 | app.UseSwaggerUI(c => |
80 | 81 | { |
81 | | - c.SwaggerEndpoint("/swagger/v1/swagger.json", "PagaAi Gateway V1"); |
| 82 | + c.SwaggerEndpoint("/swagger-proxy/usuarios", "Usuarios API"); |
| 83 | + c.SwaggerEndpoint("/swagger-proxy/clientes", "Clientes API"); |
| 84 | + c.SwaggerEndpoint("/swagger-proxy/emprestimos", "Emprestimos API"); |
| 85 | + c.SwaggerEndpoint("/swagger-proxy/notificacoes", "Notificacoes API"); |
| 86 | + c.SwaggerEndpoint("/swagger-proxy/reports", "Reports API"); |
| 87 | + c.SwaggerEndpoint("/swagger/v1/swagger.json", "Gateway V1"); |
82 | 88 | c.RoutePrefix = "swagger"; |
83 | 89 | }); |
84 | 90 |
|
|
90 | 96 | app.UseAuthentication(); |
91 | 97 | app.UseAuthorization(); |
92 | 98 |
|
| 99 | +// Proxy para swagger.json das APIs — middleware inline antes do Ocelot |
| 100 | +var swaggerProxies = new Dictionary<string, string> |
| 101 | +{ |
| 102 | + ["/swagger-proxy/usuarios"] = "http://localhost:5133/swagger/v1/swagger.json", |
| 103 | + ["/swagger-proxy/clientes"] = "http://localhost:5156/swagger/v1/swagger.json", |
| 104 | + ["/swagger-proxy/emprestimos"] = "http://localhost:5276/swagger/v1/swagger.json", |
| 105 | + ["/swagger-proxy/notificacoes"] = "http://localhost:5243/swagger/v1/swagger.json", |
| 106 | + ["/swagger-proxy/reports"] = "http://localhost:5169/swagger/v1/swagger.json", |
| 107 | +}; |
| 108 | + |
| 109 | +app.Use(async (context, next) => |
| 110 | +{ |
| 111 | + var path = context.Request.Path.Value ?? ""; |
| 112 | + if (swaggerProxies.TryGetValue(path, out var targetUrl)) |
| 113 | + { |
| 114 | + var client = context.RequestServices.GetRequiredService<IHttpClientFactory>().CreateClient(); |
| 115 | + var json = await client.GetStringAsync(targetUrl); |
| 116 | + context.Response.ContentType = "application/json"; |
| 117 | + await context.Response.WriteAsync(json); |
| 118 | + return; |
| 119 | + } |
| 120 | + await next(); |
| 121 | +}); |
| 122 | + |
93 | 123 | // Rotas de status — antes do Ocelot |
94 | 124 | app.MapGet("/", () => Results.Ok(new |
95 | 125 | { |
|
0 commit comments