You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;using Microsoft.Extensions.FileProviders;using Microsoft.Extensions.Options;using Microsoft.IdentityModel.Tokens;using Microsoft.OpenApi.Models;using NLog.Web;using Shentun.PeisReport.Api.Jwt;using System.IdentityModel.Tokens.Jwt;using System.Text;
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
// Add services to the container.
//nlog
builder.Logging.AddNLog("Configs/NLog.config");
builder.Services.AddControllers();// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();builder.Services.AddSwaggerGen(opt =>{ var baseDirectory = AppContext.BaseDirectory;
var commentsFile = Path.Combine(baseDirectory, "Shentun.PeisReport.Api.xml"); opt.IncludeXmlComments(commentsFile, true);
});
var apiGroupNames = configuration["ApiGroupName"];
builder.Services.AddSwaggerGen(c =>{ if (apiGroupNames.Contains("JianLiApi")) { c.SwaggerDoc("JianLiApi", new OpenApiInfo { Title = "����ҽԺ", Version = "V1", Description = "����ҽԺ" }); } if (apiGroupNames.Contains("QingHaiWuYuanApi")) { c.SwaggerDoc("QingHaiWuYuanApi", new OpenApiInfo { Title = "�ຣ��Ժ", Version = "V1", Description = "�ຣ��Ժ" }); } var baseDirectory = AppContext.BaseDirectory;
//����ע��
var commentsFile = Path.Combine(baseDirectory, "Shentun.PeisReport.Api.xml"); c.IncludeXmlComments(commentsFile, true);
});
builder.Services.AddCors(options =>{ options.AddPolicy("AllowAll", builder => builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader());});
var jwtHelper = new JwtHelper();
//����JWT ��֤����
builder.Services.AddAuthentication(opt =>{ opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; opt.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;}).AddJwtBearer(opt =>{ opt.TokenValidationParameters = jwtHelper.GetTokenValidationParameters();});
var app = builder.Build();
var isSwagger = Convert.ToBoolean(configuration["Swagger:IsEnabled"]);if (isSwagger){ app.UseSwagger(); //app.UseSwaggerUI();
app.UseSwaggerUI(c => { if (apiGroupNames.Contains("JianLiApi")) c.SwaggerEndpoint($"/swagger/JianLiApi/swagger.json", "����ҽԺApi"); //������ʾ
if (apiGroupNames.Contains("QingHaiWuYuanApi")) c.SwaggerEndpoint($"/swagger/QingHaiWuYuanApi/swagger.json", "�ຣ��ԺApi"); //������ʾ
//c.DefaultModelExpandDepth(-1);
});}
//����Ŀ¼
app.UseStaticFiles(new StaticFileOptions{ FileProvider = new PhysicalFileProvider(configuration["ReportVirtualPath:RealPath"]), RequestPath = configuration["ReportVirtualPath:RequestPath"]});app.UseStaticFiles(new StaticFileOptions{ FileProvider = new PhysicalFileProvider(configuration["LisReportVirtualPath:RealPath"]), RequestPath = configuration["LisReportVirtualPath:RequestPath"]});
app.UseCors("AllowAll");
app.UseAuthentication();app.UseAuthorization();
app.MapControllers();
app.Run();
|