You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.1 KiB
C#

1 year ago
using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.Core.ServiceExtensions;
using DS.WMS.Gateway;
using Microsoft.OpenApi.Models;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
var builder = WebApplication.CreateBuilder(args);
var environment = builder.Environment.EnvironmentName;
Console.WriteLine("当前开发环境:" + environment);
//注册配置
11 months ago
builder.Configuration
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
1 year ago
.AddJsonFile(path: $"appsettings.{environment}.json", optional: true, reloadOnChange: true)
.Build();
builder.Configuration.AddEnvironmentVariables();
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("ocelot.json")
.Build();
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
// builder.Services.AddSwaggerGen();
builder.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("ApiGateway", new OpenApiInfo { Title = "网关服务", Version = "v1" });
});
builder.Services.AddOcelot(configuration); //添加Ocelot服务
builder.Services.AddCorsInstall();
var app = builder.Build();
//跨域
11 months ago
var policyName = AppSetting.app(new string[] { "Cors", "PolicyName" });
1 year ago
if (!policyName.IsNullOrEmpty())
{
app.UseCors(policyName); //添加跨域中间件
}
// Configure the HTTP request pipeline.
11 months ago
// if (app.Environment.IsDevelopment())
// {
4 months ago
var apis = new List<string> { "WmsMainAPI", "WmsAdminAPI", "WmsOpAPI", "WmsFeeAPI", "WmsCheckAPI", "WmsFinanceAPI", "WmsPrintAPI", "WmsTaskAPI", "WmsContainerManagementAPI", "TestApi" };
1 year ago
app
.UseSwagger()
.UseSwaggerUI(options => { apis.ForEach(m => { options.SwaggerEndpoint($"/{m}/swagger.json", m); }); });
11 months ago
// }
// else
// {
// app.MapGet("/", () => "Hello World!");
// }
1 year ago
app.UseMiddleware<JwtSafeMiddleware>();
app.UseAuthentication(); //注意这一句的位置
app.UseAuthorization();
app.MapControllers();
app.UseOcelot().Wait(); //使用Ocelot中间件
app.Run();