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.0 KiB
C#

12 months 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);
//注册配置
10 months ago
builder.Configuration
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
12 months 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();
//跨域
10 months ago
var policyName = AppSetting.app(new string[] { "Cors", "PolicyName" });
12 months ago
if (!policyName.IsNullOrEmpty())
{
app.UseCors(policyName); //添加跨域中间件
}
// Configure the HTTP request pipeline.
10 months ago
// if (app.Environment.IsDevelopment())
// {
var apis = new List<string> { "WmsMainAPI", "WmsAdminAPI","TestApi" };
12 months ago
app
.UseSwagger()
.UseSwaggerUI(options => { apis.ForEach(m => { options.SwaggerEndpoint($"/{m}/swagger.json", m); }); });
10 months ago
// }
// else
// {
// app.MapGet("/", () => "Hello World!");
// }
12 months ago
app.UseMiddleware<JwtSafeMiddleware>();
app.UseAuthentication(); //注意这一句的位置
app.UseAuthorization();
app.MapControllers();
app.UseOcelot().Wait(); //使用Ocelot中间件
app.Run();