diff --git a/Src/Gateway/Gateway.csproj b/Src/Gateway/Gateway.csproj index 82f8dae2..4dc2203d 100644 --- a/Src/Gateway/Gateway.csproj +++ b/Src/Gateway/Gateway.csproj @@ -10,6 +10,8 @@ + + diff --git a/Src/Gateway/Program.cs b/Src/Gateway/Program.cs index b3ba8e28..5e1e7a63 100644 --- a/Src/Gateway/Program.cs +++ b/Src/Gateway/Program.cs @@ -1,16 +1,19 @@ -using Ocelot.DependencyInjection; -using Ocelot.Middleware; -var builder = WebApplication.CreateBuilder(args); -builder.Configuration.AddJsonFile("ocelot.json", true, true); -// Add services to the container. +using Gateway; -builder.Services.AddOcelot(); - -var app = builder.Build(); - -// Configure the HTTP request pipeline. - -app.UseOcelot().Wait(); - -app.Run(); +public class Program +{ + public static void Main(string[] args) + { + Host.CreateDefaultBuilder(args) + .ConfigureAppConfiguration(builder => + { + builder.AddJsonFile("ocelot.json", true, true); + }) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }) + .Build().Run(); + } +} diff --git a/Src/Gateway/Startup.cs b/Src/Gateway/Startup.cs new file mode 100644 index 00000000..87d10f71 --- /dev/null +++ b/Src/Gateway/Startup.cs @@ -0,0 +1,41 @@ +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, IWebHostEnvironment env) + { + app.UseSwagger(); + app.UseSwaggerUI(c => + { + var services = Configuration.GetSection("Services").Get>(); + foreach (var s in services) + { + c.SwaggerEndpoint($"/{s.ToLower()}/swagger/v1/swagger.json", s); + } + }); + app.UseOcelot().Wait(); + } + +} diff --git a/Src/Gateway/appsettings.json b/Src/Gateway/appsettings.json index 10f68b8c..68b1359a 100644 --- a/Src/Gateway/appsettings.json +++ b/Src/Gateway/appsettings.json @@ -5,5 +5,13 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "Services": [ + "Basic", + "Common", + "Canteen", + "Scheduled", + "User", + "Sys" + ] } diff --git a/Src/Gateway/ocelot.json b/Src/Gateway/ocelot.json index 46e3b225..52cdcdf4 100644 --- a/Src/Gateway/ocelot.json +++ b/Src/Gateway/ocelot.json @@ -84,6 +84,17 @@ "Port": 31007 } ] + }, + { + "UpstreamPathTemplate": "/{url}/swagger/v1/swagger.json", + "DownstreamPathTemplate": "/{url}/swagger/v1/swagger.json", + "DownstreamScheme": "https", + "DownstreamHostAndPorts": [ + { + "Host": "yikatong.isawesome.cn", + "Port": 443 + } + ] } ], "GlobalConfiguration": {}