Files
jinko.yikatong/Src/Gateway/Startup.cs
2024-09-05 15:46:27 +08:00

37 lines
998 B
C#

using Microsoft.OpenApi.Models;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
namespace Gateway;
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddEndpointsApiExplorer();
services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Gateway API", Version = "v1", Description = "gateway api" }); });
services.AddOcelot();
}
public void Configure(IApplicationBuilder app)
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
var services = Configuration.GetSection("Services").Get<List<string>>();
foreach (var s in services)
{
c.SwaggerEndpoint($"/{s.ToLower()}/swagger/v1/swagger.json", s);
}
});
app.UseOcelot().Wait();
}
}